diff --git a/fibonacci/fibonacci.js b/fibonacci/fibonacci.js index 65b28bb..b2d7689 100644 --- a/fibonacci/fibonacci.js +++ b/fibonacci/fibonacci.js @@ -1,5 +1,13 @@ -var fibonacci = function() { +const fibonacci = function(count) { + if (count < 0) return "OOPS"; + let a = 0; + let b = 1; + for (let i = 1; i < count; i++) { + const temp = b; + b = a + b; + a = temp; + } + return b; +}; -} - -module.exports = fibonacci +module.exports = fibonacci; diff --git a/fibonacci/fibonacci.spec.js b/fibonacci/fibonacci.spec.js index 956e418..9146992 100644 --- a/fibonacci/fibonacci.spec.js +++ b/fibonacci/fibonacci.spec.js @@ -1,25 +1,25 @@ -var fibonacci = require('./fibonacci') +const fibonacci = require("./fibonacci"); -describe('fibonacci', function() { - it('works', function() { +describe("fibonacci", () => { + it("works", () => { expect(fibonacci(4)).toEqual(3); }); - xit('works', function() { + it("works", () => { expect(fibonacci(6)).toEqual(8); }); - xit('works', function() { + it("works", () => { expect(fibonacci(10)).toEqual(55); }); - xit('works', function() { + it("works", () => { expect(fibonacci(15)).toEqual(610); }); - xit('works', function() { + it("works", () => { expect(fibonacci(25)).toEqual(75025); }); - xit('doesn\'t accept negatives', function() { + it("doesn't accept negatives", () => { expect(fibonacci(-25)).toEqual("OOPS"); }); - xit('DOES accept strings', function() { + it("DOES accept strings", () => { expect(fibonacci("8")).toEqual(21); }); });