This commit is contained in:
Philippe Torrel
2026-07-02 13:11:49 +02:00
parent 253411f3c9
commit f0dd230fe9
8 changed files with 91 additions and 6 deletions

View File

@@ -1,4 +1,4 @@
<!DOCTYPE html> <!doctype html>
<html lang="de"> <html lang="de">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
@@ -23,6 +23,8 @@
const findDeepestLevel = (arr, currentLevel = 1) => {}; const findDeepestLevel = (arr, currentLevel = 1) => {};
// Array.isArray()
// Test cases // Test cases
console.log(findDeepestLevel([1, [2, [3, [4]], 5]])); // => 4 console.log(findDeepestLevel([1, [2, [3, [4]], 5]])); // => 4
console.log(findDeepestLevel([1, 2, 3, 4, 5])); // => 1 console.log(findDeepestLevel([1, 2, 3, 4, 5])); // => 1

View File

@@ -1,4 +1,4 @@
<!DOCTYPE html> <!doctype html>
<html lang="de"> <html lang="de">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
@@ -20,9 +20,47 @@
<script> <script>
'use strict'; 'use strict';
const findMax = (arr) => {}; const findMax2 = (ar) => {
if (ar.length === 0) return null;
if (ar.length === 1) return ar[0];
let max = ar[0];
let i = -1;
while (++i < ar.length) {
if (ar[i] > max) {
max = ar[i];
}
}
return max;
};
const findMax = (arr) => {
// Basisfall
if (arr.length === 0) {
return null;
}
if (arr.length === 1) {
return arr[0];
}
return Math.max(arr[0], findMax(arr.slice(1))); // Rekursion
// return arr.length === 0 ? null : arr.length === 1 ? arr[0] : Math.max(arr[0], findMax(arr.slice(1)));
};
// Test cases // Test cases
console.time('rekursion max');
console.log(findMax([1, 5, 3])); // => 5
console.timeEnd('rekursion max');
console.time('Math.max');
console.log(Math.max(...[1, 5, 3]));
console.timeEnd('Math.max');
console.time('for');
console.log(findMax2([1, 5, 3]));
console.timeEnd('for');
console.log(findMax([1, 5, 3, 9, 2])); // => 9 console.log(findMax([1, 5, 3, 9, 2])); // => 9
console.log(findMax([-10, -20, -3, -4])); // => -3 console.log(findMax([-10, -20, -3, -4])); // => -3
console.log(findMax([42])); // => 42 console.log(findMax([42])); // => 42

View File

@@ -47,7 +47,7 @@
}, },
); );
// Empfholene Schreibweise - then nur für "Erfolg" (resolve) - catch für "Fehler" (reject) // Empfohlene Schreibweise - then nur für "Erfolg" (resolve) - catch für "Fehler" (reject)
promise promise
.then((result) => { .then((result) => {
console.log('OK: ', result); console.log('OK: ', result);

View File

@@ -12,7 +12,7 @@
} }
.menu-main { .menu-main {
background-color: steelblue; background-color: tomato;
} }
.menu-main ul { .menu-main ul {
list-style: none; list-style: none;

View File

@@ -21,7 +21,7 @@
// Menu Main // Menu Main
.menu-main { .menu-main {
background-color: steelblue; background-color: tomato;
ul { ul {
list-style: none; list-style: none;
display: flex; display: flex;

View File

@@ -0,0 +1,4 @@
name, category, price
Klingon Letter Opener, Office Warfare, 19.99
Backpack of Holding, Travel, 29.99
Tardis Alarmclock, Merchandise, 15.99
1 name category price
2 Klingon Letter Opener Office Warfare 19.99
3 Backpack of Holding Travel 29.99
4 Tardis Alarmclock Merchandise 15.99

View File

@@ -0,0 +1,28 @@
// fs = FileSystem Modul aus der Node Standardbib
const fs = require('fs'); // commonjs - Node Schreibweise
// Funktion mir einem asynchronen Prozess
const getContentBy = (path) => {
return new Promise((resolve, reject) => {
// asynchroner Prozess
fs.readFile(path, 'utf-8', (err, data) => {
if (err) {
// console.error(err);
reject(err);
}
// console.log(data);
resolve(data);
});
});
};
// Funktionsaufruf einer Funktion mit asynchronem Prozess
getContentBy('data/productss.csv')
.then((data) => {
console.log(data);
})
.catch((err) => {
console.error(err);
});
console.log('weiter im code...');

View File

@@ -0,0 +1,13 @@
{
"name": "01_promise-and-readfile",
"version": "1.0.0",
"description": "",
"license": "ISC",
"author": "",
"type": "commonjs",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": []
}