feat: added 03_dom

This commit is contained in:
Philippe Torrel
2026-07-13 10:38:22 +02:00
parent 6292cabfee
commit e0bd3930d9
134 changed files with 21947 additions and 26 deletions

View File

@@ -1,10 +1,11 @@
<!DOCTYPE html>
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Übung 5: Summe einer Zahlenreihe rekursiv berechnen</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>
</head>
<body>
<main>
@@ -28,10 +29,29 @@
<script>
'use strict';
const sumRecursive = (n) => {};
const sumRecursive = (n) => {
if (n === 0) {
return 0;
}
return n + sumRecursive(n - 1); // 5 + 4 + 3 + 2 + 1 + 0
};
const sumReduce = (n) => {
return _.range(0, n + 1).reduce((a, b) => a + b, 0);
};
// Test Cases
console.log(_.range(5)); // => [0,1,2,3,4]
console.log(_.range(2, 5)); // => [2,3,4]
console.log(_.range(2, 10, 2)); // => [2,4,6,8]
console.time('recursive');
console.log(sumRecursive(5)); // => 15 (5 + 4 + 3 + 2 + 1)
console.timeEnd('recursive');
console.time('reduce');
console.log(sumReduce(5)); // => 15 (5 + 4 + 3 + 2 + 1)
console.timeEnd('reduce');
console.log(sumRecursive(10)); // => 55 (10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1)
console.log(sumRecursive(0)); // => 0
</script>