odin-default-js-exercises/fibonacci/fibonacci.js

15 lines
255 B
JavaScript
Raw Normal View History

2017-12-15 17:01:24 +00:00
const fibonacci = function(count) {
if (count < 0) return "OOPS";
2020-01-29 16:52:57 +00:00
if (count == 0) return 0;
2017-12-15 17:01:24 +00: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 19:29:48 +00:00
2017-12-15 17:01:24 +00:00
module.exports = fibonacci;