2024-01-11 20:37:42 +00:00
|
|
|
const fibonacci = function(number) {
|
2024-01-11 20:39:13 +00:00
|
|
|
if (number == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (number < 0) {
|
|
|
|
return "OOPS";
|
|
|
|
}
|
2024-01-11 20:37:42 +00:00
|
|
|
let a = 1, b = 1;
|
|
|
|
let sum = a;
|
|
|
|
for (let i = 0;
|
2024-01-11 20:35:00 +00:00
|
|
|
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;
|