Skip to content

Instantly share code, notes, and snippets.

@loraxx753
Last active October 3, 2019 01:29
Show Gist options
  • Save loraxx753/ba08770d7d0e3c6d8664b07cfee360cb to your computer and use it in GitHub Desktop.
Save loraxx753/ba08770d7d0e3c6d8664b07cfee360cb to your computer and use it in GitHub Desktop.
small Fibonacci sequence
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