This commit is contained in:
@@ -14,6 +14,10 @@ const getFileBy = (path = '', encoding = 'utf-8') => {
|
||||
Promise.all([
|
||||
getFileBy('data/file-01.txt'),
|
||||
getFileBy('data/file-02.txt'),
|
||||
// (() =>
|
||||
// new Promise((resolve, reject) => {
|
||||
// return reject(new Error('something went wrong'));
|
||||
// }))(),
|
||||
getFileBy('data/file-03.txt'),
|
||||
getFileBy('data/file-04.txt'),
|
||||
getFileBy('data/file-05.txt'),
|
||||
|
||||
@@ -22,6 +22,10 @@
|
||||
['Clara', 76, 95, 89],
|
||||
];
|
||||
|
||||
console.log(gradesTable[0][2]); //=> 'English'
|
||||
console.log(gradesTable[1][0]); //=> 'Anna'
|
||||
console.log(gradesTable[1][2]); //=> 92
|
||||
|
||||
console.log(gradesTable[3][2]); // => 95
|
||||
console.log(['Clara', 76, 95, 89][2]); // => 95
|
||||
console.log(gradesTable[1][3]); // => 78
|
||||
@@ -40,59 +44,98 @@
|
||||
gradesTable.push(['Benjamin', 99, 90, 75]);
|
||||
|
||||
// TODO: optionale Übung: gradeTable in gradesObject über eigene Funktion parseToObj() umwandeln. Tipp: map. Beispiel 02_csv-to-obj.html aus Tag 12
|
||||
const gradesTableObj = [
|
||||
{
|
||||
name: 'Anna',
|
||||
scores: [
|
||||
{
|
||||
name: 'Mathematics',
|
||||
score: 85,
|
||||
},
|
||||
{
|
||||
name: 'English',
|
||||
score: 92,
|
||||
},
|
||||
{
|
||||
name: 'Biology',
|
||||
score: 78,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Ben',
|
||||
scores: [
|
||||
{
|
||||
name: 'Mathematics',
|
||||
score: 76,
|
||||
},
|
||||
{
|
||||
name: 'English',
|
||||
score: 95,
|
||||
},
|
||||
{
|
||||
name: 'Biology',
|
||||
score: 89,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Clara',
|
||||
scores: [
|
||||
{
|
||||
name: 'Mathematics',
|
||||
score: 85,
|
||||
},
|
||||
{
|
||||
name: 'English',
|
||||
score: 92,
|
||||
},
|
||||
{
|
||||
name: 'Biology',
|
||||
score: 78,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
/*
|
||||
[
|
||||
['Name', 'Mathematics', 'English', 'Biology'],
|
||||
['Anna', 85, 92, 78],
|
||||
['Ben', 90, 88, 84],
|
||||
['Clara', 76, 95, 89],
|
||||
];
|
||||
*/
|
||||
|
||||
const parseToObj = (arr) => {
|
||||
let returnTable = [];
|
||||
console.log(arr);
|
||||
|
||||
// Students Array
|
||||
for (let studentIdx = 1; studentIdx < arr.length; studentIdx++) {
|
||||
let obj = {
|
||||
name: arr[studentIdx][0],
|
||||
scores: [],
|
||||
};
|
||||
|
||||
// scores Array
|
||||
for (let classIdx = 1; classIdx < arr[0].length; classIdx++) {
|
||||
let classObj = {};
|
||||
|
||||
classObj.name = arr[0][classIdx];
|
||||
classObj.score = arr[studentIdx][classIdx];
|
||||
|
||||
obj.scores.push(classObj);
|
||||
}
|
||||
|
||||
returnTable.push(obj);
|
||||
}
|
||||
|
||||
return returnTable;
|
||||
};
|
||||
|
||||
const gradesTableObj = parseToObj(gradesTable);
|
||||
|
||||
// const gradesTableObj = [
|
||||
// {
|
||||
// name: 'Anna',
|
||||
// scores: [
|
||||
// {
|
||||
// name: 'Mathematics',
|
||||
// score: 85,
|
||||
// },
|
||||
// {
|
||||
// name: 'English',
|
||||
// score: 92,
|
||||
// },
|
||||
// {
|
||||
// name: 'Biology',
|
||||
// score: 78,
|
||||
// },
|
||||
// ],
|
||||
// },
|
||||
// {
|
||||
// name: 'Ben',
|
||||
// scores: [
|
||||
// {
|
||||
// name: 'Mathematics',
|
||||
// score: 76,
|
||||
// },
|
||||
// {
|
||||
// name: 'English',
|
||||
// score: 95,
|
||||
// },
|
||||
// {
|
||||
// name: 'Biology',
|
||||
// score: 89,
|
||||
// },
|
||||
// ],
|
||||
// },
|
||||
// {
|
||||
// name: 'Clara',
|
||||
// scores: [
|
||||
// {
|
||||
// name: 'Mathematics',
|
||||
// score: 85,
|
||||
// },
|
||||
// {
|
||||
// name: 'English',
|
||||
// score: 92,
|
||||
// },
|
||||
// {
|
||||
// name: 'Biology',
|
||||
// score: 78,
|
||||
// },
|
||||
// ],
|
||||
// },
|
||||
// ];
|
||||
|
||||
console.log(JSON.stringify(gradesTableObj, null, 2));
|
||||
|
||||
@@ -140,6 +183,7 @@
|
||||
|
||||
console.log(inventory[1][1][2]); // => 30
|
||||
console.log(inventory[2][0][1]); // => 'Milk'
|
||||
console.log(inventory[3][0][1]); // => 'GTA6'
|
||||
|
||||
const inventoryObj = {
|
||||
floors: [
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
|
||||
const letterToChessIndex = (letter) => 'abcdefgh'.indexOf(letter);
|
||||
// => 'e' -> 4 <- Array Spalte (x)
|
||||
const numberToChessIndex = (num) => 8 - num; // => '2' -> 6 <- Array Zeile (y)
|
||||
const numberToChessIndex = (num) => 8 - Number(num); // => '2' -> 6 <- Array Zeile (y)
|
||||
|
||||
const fieldToXPosition = (field) => letterToChessIndex(field.charAt(0));
|
||||
// => 'e2' -> 'e' -> letterToChessIndex('e') -> 4
|
||||
|
||||
Reference in New Issue
Block a user