forked from M3-Academy/challenge-algorithms-v2.0
feature: resolve exercício 04-fibonacci
This commit is contained in:
parent
b38e95acb3
commit
f946f2186f
@ -1,4 +1,15 @@
|
||||
export function fibonacci(value) {
|
||||
// implementar logica aqui
|
||||
let beforeLastNumber = 0;
|
||||
let lastNumber = 1;
|
||||
let nextNumber;
|
||||
|
||||
if (value < 2) return value;
|
||||
|
||||
for (let i = 2; i <= value; i++) {
|
||||
nextNumber = lastNumber + beforeLastNumber;
|
||||
beforeLastNumber = lastNumber;
|
||||
lastNumber = nextNumber;
|
||||
}
|
||||
|
||||
return lastNumber;
|
||||
}
|
Loading…
Reference in New Issue
Block a user