Skip to content

Instantly share code, notes, and snippets.

@proprietary
Last active January 10, 2016 21:20
Show Gist options
  • Save proprietary/0dcb6393dd304718c3f1 to your computer and use it in GitHub Desktop.
Save proprietary/0dcb6393dd304718c3f1 to your computer and use it in GitHub Desktop.
Showing off cool ES6/7 features
/* This would be slow as hell in practice
* because the algorithm is quadratic; the list
* is recomputed every time. But oh, the
* simplicity is refreshing.
*
* Exercise for you, gist reader: implement
* this same thing with Immutable.js.
*/
function fibs([...nums], max) {
let next = [...nums].slice(-2).reduce((x, y) => x + y);
if(next > max) {
return [...nums];
}
return fibs([...nums, next], max);
}
//Example:
(function() {
let r = fibs([0, 1], 1000);
console.log(r);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment