Skip to content

Instantly share code, notes, and snippets.

@kdnk
Created November 30, 2016 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdnk/102ed7128c917a96bdbc0d490afbf69d to your computer and use it in GitHub Desktop.
Save kdnk/102ed7128c917a96bdbc0d490afbf69d to your computer and use it in GitHub Desktop.
let count = 0
let memo = [1, 1]
main()
function main () {
let a = []
for (let i = 0; i < 20; i++) {
a.push(fibonacci(i))
}
console.log('count ', count)
printArray(a)
}
function fibonacci (n) {
count = count + 1
if (memo[n]) {
return memo[n]
} else {
const t = fibonacci(n - 1) + fibonacci(n - 2)
memo[n] = t
return t
}
}
function printArray (a) {
b = a.join(' ')
console.log(b)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment