Skip to content

Commit 0f387f3

Browse files
committed
Fibonacci gelöst
1 parent bb26d8f commit 0f387f3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/exercises/fibonacci.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,17 @@
22

33
// Berechne die Fibonacci Folge für n Elemente, beginnend bei 0.
44
// Gib alle berechneten Elemente aus.
5+
function fibonacci (anzahlElemente){
6+
let fibonacciArr = [0, 1]
7+
8+
for (let i = 2; fibonacciArr.length < anzahlElemente; i++) {
9+
console.log(i)
10+
fibonacciArr.push(fibonacciArr[i-2] + fibonacciArr[i-1])
11+
}
12+
return fibonacciArr
13+
}
14+
15+
let result = fibonacci(10)
16+
console.log(result)
17+
18+

0 commit comments

Comments
 (0)