2022-02-20 19:07:44 +00:00
|
|
|
const fibonacci = function (count) {
|
2023-01-21 17:53:41 +00:00
|
|
|
if (count < 0) return "OOPS";
|
|
|
|
if (count === 0) return 0;
|
|
|
|
let a = 0;
|
|
|
|
let b = 1;
|
|
|
|
for (let i = 1; i < count; i++) {
|
|
|
|
const temp = b;
|
|
|
|
b = a + b;
|
|
|
|
a = temp;
|
|
|
|
}
|
|
|
|
return b;
|
2022-02-20 19:07:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = fibonacci;
|