Last active
October 3, 2019 01:29
-
-
Save loraxx753/ba08770d7d0e3c6d8664b07cfee360cb to your computer and use it in GitHub Desktop.
small Fibonacci sequence
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
const fibonacci = (n) => { | |
const a = Array(n).fill(0) | |
return a.map((_, i) => a[i] = (i < 2) ? 1 : a[i-1] + a[i-2]) | |
} | |
/** This would work if the third parameter of map was a pointer to the array and not a copy :( **/ | |
// const fibonacci = (n) => Array(n).fill(0).map((_, i, a) => a[i] = (i < 2) ? 1 : a[i-1] + a[i-2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment