2017-12-15 09:01:24 -08:00
|
|
|
const fibonacci = function(count) {
|
|
|
|
if (count < 0) return "OOPS";
|
2020-01-29 08:52:57 -08:00
|
|
|
if (count == 0) return 0;
|
2017-12-15 09:01:24 -08:00
|
|
|
let a = 0;
|
|
|
|
let b = 1;
|
|
|
|
for (let i = 1; i < count; i++) {
|
|
|
|
const temp = b;
|
|
|
|
b = a + b;
|
|
|
|
a = temp;
|
|
|
|
}
|
|
|
|
return b;
|
|
|
|
};
|
2017-08-25 12:29:48 -07:00
|
|
|
|
2017-12-15 09:01:24 -08:00
|
|
|
module.exports = fibonacci;
|