forked from M3-Academy/challenge-algorithms-v2.0
16 lines
313 B
JavaScript
16 lines
313 B
JavaScript
export function fibonacci(value) {
|
|
let vet = [];
|
|
vet.push(0);
|
|
vet.push(1);
|
|
if (value == 0) {
|
|
return vet[0];
|
|
} else if (value == 1) {
|
|
return vet[1];
|
|
} else {
|
|
for (let index = 2; index <= value; index++) {
|
|
vet[index] = vet[index - 2] + vet[index - 1];
|
|
}
|
|
}
|
|
return vet.at(-1);
|
|
}
|