From d42eebaab872f276ce13cdc50add0ab7a4166aaf Mon Sep 17 00:00:00 2001 From: Cody Loyd Date: Fri, 15 Dec 2017 11:01:24 -0600 Subject: [PATCH] solutions --- fibonacci/fibonacci.js | 16 ++++++++++++---- fibonacci/fibonacci.spec.js | 18 +++++++++--------- 2 files changed, 21 insertions(+), 13 deletions(-) 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); }); });