• JavaScript Teaser: Fabulous Fibonacci

    Summary
    Fill in the missing line of the following code that implements a function returning the next Fibonacci number every time it's called.

    Reading time: 1 minute
    Written by
    Date published
    June 5, 2015

    Fill in the missing line of the following code that implements a function returning the next Fibonacci number every time it's called.

      var nextFibonacciNumber = (function() {
        var s = [0, 1];
        return function () {
          // Fill in the missing line here.
          return s.shift();
        };
      })();
    

    You should only need to add a single statement, consisting of less than 25 characters.

    Please post the answer on JSFiddle or similar service, and then post a link to your answer below (so that other people still have a chance to solve it). You can also post other thoughts or email Rangle.io's CTO, Yuri@rangle.io, if you wish to share further ideas.

    Tags

    See what Ranglers are writing about on our blog