20 lines
375 B
JavaScript
20 lines
375 B
JavaScript
const fibonacci = function(number) {
|
|
if (number == 0) {
|
|
return 0;
|
|
}
|
|
if (number < 0) {
|
|
return "OOPS";
|
|
}
|
|
let a = 1, b = 1;
|
|
let sum = a;
|
|
for (let i = 0;
|
|
i < number - 2;
|
|
i++, (i % 2 == 0) ? a = sum : b = sum) {
|
|
sum = a + b;
|
|
}
|
|
return sum;
|
|
};
|
|
|
|
// Do not edit below this line
|
|
module.exports = fibonacci;
|