Created
June 11, 2018 16:34
-
-
Save mcabreradev/f4e57e9913cdf63d45a5eb5cbcd67b22 to your computer and use it in GitHub Desktop.
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
// 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