Created
February 20, 2022 09:24
-
-
Save dkokic/04ebf5d08729e9bb0ab85cf8d69410dd to your computer and use it in GitHub Desktop.
purely functional implementation of the fibonacci function (including optimisation via memoization)
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 fibonacci = (n) => n < 3 ? 1 : fibonacci(n - 1) + fibonacci(n - 2) | |
const fibonacci = (n, memo = { 1: 1, 2: 1 }) => n in memo ? memo[n] : memo[n] = fibonacci(n - 1) + fibonacci(n - 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment