Skip to content

Instantly share code, notes, and snippets.

@behcet
Created June 14, 2017 23:09
Show Gist options
  • Save behcet/8d1dad05095e4db3378b6d4fd0012b2a to your computer and use it in GitHub Desktop.
Save behcet/8d1dad05095e4db3378b6d4fd0012b2a to your computer and use it in GitHub Desktop.
Fibonacci closure
const fib = (function fib () {
var prev = [ 0, 0 ];
return () => {
let value = prev.shift() + Math.max(prev.find(i => i > -1), 1);
prev.push(value);
return value;
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment