This commit is contained in:
Philippe Torrel
2026-09-24 12:13:28 +02:00
parent 6887814561
commit 8a51ee133a
19 changed files with 411 additions and 0 deletions
@@ -0,0 +1 @@
Ich bin file 01
@@ -0,0 +1 @@
Ich bin file 02
@@ -0,0 +1 @@
Ich bin file 03
@@ -0,0 +1 @@
Ich bin file 04
@@ -0,0 +1 @@
Ich bin file 05
@@ -0,0 +1,26 @@
import fs from 'node:fs';
import color from 'chalk';
const getFileBy = (path = '', encoding = 'utf-8') => {
return fs.promises.readFile(path, encoding);
};
// getFileBy('data/file-01.txt')
// .then((data) => {
// console.log(color.green(data));
// })
// .catch((err) => console.log(color.red(err)));
Promise.all([
getFileBy('data/file-01.txt'),
getFileBy('data/file-02.txt'),
getFileBy('data/file-03.txt'),
getFileBy('data/file-04.txt'),
getFileBy('data/file-05.txt'),
])
.then((data) => {
console.log(data);
})
.catch((err) => {
console.log(err);
});
@@ -0,0 +1,28 @@
{
"name": "02_promise-all",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "02_promise-all",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"chalk": "^6.0.0"
}
},
"node_modules/chalk": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-6.0.0.tgz",
"integrity": "sha512-2uNTXIuTTxk7ciZgAU1BQcgnchcG0xXnrs6jzkQfj9SsRa9M2s5zE8WT96hS6KmG4MzWHSrvH43DF1m4XRkrFg==",
"license": "MIT",
"engines": {
"node": ">=22"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
}
}
}
@@ -0,0 +1,16 @@
{
"name": "02_promise-all",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "module",
"description": "",
"dependencies": {
"chalk": "^6.0.0"
}
}
@@ -0,0 +1 @@
Ich bin file 01
@@ -0,0 +1 @@
Ich bin file 02
@@ -0,0 +1 @@
Ich bin file 03
@@ -0,0 +1 @@
Ich bin file 04
@@ -0,0 +1 @@
Ich bin file 05
@@ -0,0 +1,29 @@
import fs from 'node:fs';
import color from 'chalk';
const getPromiseFileBy = (path = '', encoding = 'utf-8') => {
return new Promise((resolve, reject) => {
fs.readFile(path, encoding, (error, data) => {
if (error) reject(error);
resolve(data);
});
});
};
// async ... await
const getFileBy = async (path = '', encoding = 'utf-8') => {
try {
const result = await fs.promises.readFile(path, encoding);
console.log(color.magenta(result));
return result;
} catch (error) {
console.log(error);
throw new Error(error);
}
};
getFileBy('data/file-01.txt')
.then((data) => {
console.log(color.green(data));
})
.catch((err) => console.log(color.red(err)));
@@ -0,0 +1,28 @@
{
"name": "02_promise-all",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "02_promise-all",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"chalk": "^6.0.0"
}
},
"node_modules/chalk": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-6.0.0.tgz",
"integrity": "sha512-2uNTXIuTTxk7ciZgAU1BQcgnchcG0xXnrs6jzkQfj9SsRa9M2s5zE8WT96hS6KmG4MzWHSrvH43DF1m4XRkrFg==",
"license": "MIT",
"engines": {
"node": ">=22"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
}
}
}
@@ -0,0 +1,16 @@
{
"name": "03_aync-await",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "module",
"description": "",
"dependencies": {
"chalk": "^6.0.0"
}
}
@@ -0,0 +1,168 @@
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Mehrdimensionales Array</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<main>
<div class="container py-5">
<h1>Mehrdimensionales Array</h1>
</div>
</main>
<script>
'use strict';
const gradesTable = [
['Name', 'Mathematics', 'English', 'Biology'],
['Anna', 85, 92, 78],
['Ben', 90, 88, 84],
['Clara', 76, 95, 89],
];
console.log(gradesTable[3][2]); // => 95
console.log(['Clara', 76, 95, 89][2]); // => 95
console.log(gradesTable[1][3]); // => 78
// Access to Anna's math grade
const annasMathGrade = gradesTable[1][1]; // => 85
// Access to Clara's biology grade
const clarasBioGrade = gradesTable[3][3]; // => 89
// Change Anna's math grade to 88
gradesTable[1][1] = 88;
gradesTable[1].splice(1, 1, 88);
// Add a new row for another student
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,
},
],
},
];
console.log(JSON.stringify(gradesTableObj, null, 2));
// ===============
const shoppingList = [
['Fruits', 'Apples', 'Bananas', 'Oranges'],
['Vegetables', 'Carrots', 'Broccoli', 'Spinach'],
['Dairy', 'Milk', 'Cheese', 'Yogurt'],
];
console.log(shoppingList);
// Access to the second type of vegetable
const secondVegetable = shoppingList[1][2]; // => 'Broccoli'
console.log(shoppingList[1][3]); // => 'Spinach'
console.log(shoppingList[2][1]); // => 'Milk'
// ===============
const inventory = [
[
// Category: Electronics
['Shelf 1', 'Laptop', 10],
['Shelf 2', 'Smartphone', 25],
],
[
// Category: Clothing
['Shelf 1', 'T-Shirts', 50],
['Shelf 2', 'Jeans', 30],
],
[
// Category: Groceries
['Shelf 1', 'Milk', 100],
['Shelf 2', 'Bread', 80],
],
[
// Category: Games
['Shelf 1', 'GTA6', 80],
['Shelf 2', 'Counter Strike', 30],
['Shelf 3', 'Among US', 80],
['Shelf 4', 'Mechabellum', 80],
],
];
console.log(inventory[1][1][2]); // => 30
console.log(inventory[2][0][1]); // => 'Milk'
const inventoryObj = {
floors: [
{
name: 'Electronics',
shelfs: [
{
name: 'Shelf 1',
products: [
{
name: 'Laptop',
quantity: 10,
},
{
name: 'Smartphone',
quantity: 25,
},
],
},
],
},
],
};
</script>
</body>
</html>
@@ -0,0 +1,45 @@
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Chess Vorlage</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<main>
<div class="container py-5">
<h1>Chess Vorlage</h1>
</div>
</main>
<script>
'use strict';
const boardInStartPosition = [
['♜', '♞', '♝', '♛', '♚', '♝', '♞', '♜'],
['♟', '♟', '♟', '♟', '♟', '♟', '♟', '♟'],
['◻', '▦', '◻', '▦', '◻', '▦', '◻', '▦'],
['▦', '◻', '▦', '◻', '▦', '◻', '▦', '◻'],
['◻', '▦', '◻', '▦', '◻', '▦', '◻', '▦'],
['▦', '◻', '▦', '◻', '▦', '◻', '▦', '◻'],
['♙', '♙', '♙', '♙', '♙', '♙', '♙', '♙'],
['♖', '♘', '♗', '♕', '♔', '♗', '♘', '♖'],
];
console.log(boardInStartPosition[7][6]); // => '♘'
console.log(boardInStartPosition[5][5]); // => '◻'
// Im Schachjargon: 'g1f3'
const emptyBoard = [
['◻', '▦', '◻', '▦', '◻', '▦', '◻', '▦'],
['▦', '◻', '▦', '◻', '▦', '◻', '▦', '◻'],
['◻', '▦', '◻', '▦', '◻', '▦', '◻', '▦'],
['▦', '◻', '▦', '◻', '▦', '◻', '▦', '◻'],
['◻', '▦', '◻', '▦', '◻', '▦', '◻', '▦'],
['▦', '◻', '▦', '◻', '▦', '◻', '▦', '◻'],
['◻', '▦', '◻', '▦', '◻', '▦', '◻', '▦'],
['▦', '◻', '▦', '◻', '▦', '◻', '▦', '◻'],
];
</script>
</body>
</html>
@@ -0,0 +1,45 @@
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Chess Vorlage</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<main>
<div class="container py-5">
<h1>Chess Vorlage</h1>
</div>
</main>
<script>
'use strict';
const boardInStartPosition = [
['♜', '♞', '♝', '♛', '♚', '♝', '♞', '♜'],
['♟', '♟', '♟', '♟', '♟', '♟', '♟', '♟'],
['◻', '▦', '◻', '▦', '◻', '▦', '◻', '▦'],
['▦', '◻', '▦', '◻', '▦', '◻', '▦', '◻'],
['◻', '▦', '◻', '▦', '◻', '▦', '◻', '▦'],
['▦', '◻', '▦', '◻', '▦', '◻', '▦', '◻'],
['♙', '♙', '♙', '♙', '♙', '♙', '♙', '♙'],
['♖', '♘', '♗', '♕', '♔', '♗', '♘', '♖'],
];
console.log(boardInStartPosition[7][6]); // => '♘'
console.log(boardInStartPosition[5][5]); // => '◻'
// Im Schachjargon: 'g1f3'
const emptyBoard = [
['◻', '▦', '◻', '▦', '◻', '▦', '◻', '▦'],
['▦', '◻', '▦', '◻', '▦', '◻', '▦', '◻'],
['◻', '▦', '◻', '▦', '◻', '▦', '◻', '▦'],
['▦', '◻', '▦', '◻', '▦', '◻', '▦', '◻'],
['◻', '▦', '◻', '▦', '◻', '▦', '◻', '▦'],
['▦', '◻', '▦', '◻', '▦', '◻', '▦', '◻'],
['◻', '▦', '◻', '▦', '◻', '▦', '◻', '▦'],
['▦', '◻', '▦', '◻', '▦', '◻', '▦', '◻'],
];
</script>
</body>
</html>