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

15 lines
256 B
JavaScript
Raw Permalink Normal View History

const fibonacci = function(count) {
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;
};
2017-08-25 19:29:48 +00:00
module.exports = fibonacci;