Skip to content

Instantly share code, notes, and snippets.

@mcabreradev
Created June 11, 2018 16:34
Show Gist options
  • Save mcabreradev/f4e57e9913cdf63d45a5eb5cbcd67b22 to your computer and use it in GitHub Desktop.
Save mcabreradev/f4e57e9913cdf63d45a5eb5cbcd67b22 to your computer and use it in GitHub Desktop.
// Initialize an empty array of length n. Use Array.prototype.reduce() to add values into the array, using the sum of the last two values, except for the first two.
const fibonacci = n =>
[...Array(n)].reduce(
(acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i),
[]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment