odin-js-fundamentals-part-5/10_fibonacci/fibonacci.js

13 lines
268 B
JavaScript
Raw Normal View History

2024-01-11 20:35:00 +00:00
const fibonacci = function(number, b) {
let sum;
for (let i = 0, a = 1, b = 1;
i < number - 2;
i++, (i % 2 == 0) ? a = sum : b = sum) {
sum = a + b;
}
return sum;
2024-01-11 08:52:05 +00:00
};
// Do not edit below this line
module.exports = fibonacci;