From 10a2db696a7fdf9619ad3d1f7a555a14bec41215 Mon Sep 17 00:00:00 2001 From: Philippe Torrel Date: Fri, 25 Sep 2026 09:23:21 +0200 Subject: [PATCH] --- .../unterricht/tag14/02_promise-all/index.js | 4 + .../tag14/04_mehrdim-array/index.html | 148 ++++++++++++------ .../unterricht/tag14/06_chess-move/index.html | 2 +- 3 files changed, 101 insertions(+), 53 deletions(-) diff --git a/02_advanced/unterricht/tag14/02_promise-all/index.js b/02_advanced/unterricht/tag14/02_promise-all/index.js index bcfe226..884fb2c 100644 --- a/02_advanced/unterricht/tag14/02_promise-all/index.js +++ b/02_advanced/unterricht/tag14/02_promise-all/index.js @@ -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'), diff --git a/02_advanced/unterricht/tag14/04_mehrdim-array/index.html b/02_advanced/unterricht/tag14/04_mehrdim-array/index.html index 6b3c0f7..53b211a 100644 --- a/02_advanced/unterricht/tag14/04_mehrdim-array/index.html +++ b/02_advanced/unterricht/tag14/04_mehrdim-array/index.html @@ -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: [ diff --git a/02_advanced/unterricht/tag14/06_chess-move/index.html b/02_advanced/unterricht/tag14/06_chess-move/index.html index d2b346d..97eb83a 100644 --- a/02_advanced/unterricht/tag14/06_chess-move/index.html +++ b/02_advanced/unterricht/tag14/06_chess-move/index.html @@ -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