Last active
September 16, 2019 12:34
-
-
Save NathanKleekamp/38d9b4a10148f42176b8a6b349932083 to your computer and use it in GitHub Desktop.
A recursive Fibonacci Sequence generator
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
const fib = (count, result = [0, 1]) => { | |
if (count <= 2 || count === 0) { | |
return result; | |
} | |
const { length } = result; | |
return fib(count - 1, result.concat(result[length - 1] + result[length - 2])); | |
}; | |
const fib5 = fib(5) // [0, 1, 1, 2, 3] | |
const fib10 = fib(10) // [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment