Fibonacci generator using EcmaScript 6 (es6)


Thanks to this video:



An iterator will return an object that has the value, and a done flag that tells you whether the generator is finished. { value: 0, done: false }.

Then when you call you will get this response object: { value: 1, done: false }. In this example, the generator goes on forever, so it would never produce done: true.

Here is a link to the gist:

  • 112864

    you can do [val1, val2] = [val2, val1]