Skip to content

Instantly share code, notes, and snippets.

@colus001
Last active July 3, 2017 11:30
Show Gist options
  • Save colus001/c1fc63d36affcd5b2b168b3bf734658a to your computer and use it in GitHub Desktop.
Save colus001/c1fc63d36affcd5b2b168b3bf734658a to your computer and use it in GitHub Desktop.
Fibonacci number generator with memoization in Javascript
var fibonacci = (() => {
const memo = [0, 1]
return n => (
memo[n] >= 0
? 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