Last active
January 10, 2016 21:20
-
-
Save proprietary/0dcb6393dd304718c3f1 to your computer and use it in GitHub Desktop.
Showing off cool ES6/7 features
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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