-
-
Save waaronking/30882993f61e6f1e52f5 to your computer and use it in GitHub Desktop.
Fibonacci Sequence (The cool way)
This file contains hidden or 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
var fibonacci = function(n) { | |
return Array.apply(null, Array(n)) | |
.reduce(function(sequence, value, index) { | |
return sequence.concat((index < 2) ? index : sequence[index - 1] + sequence[index - 2]); | |
}, []); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment