Created
November 30, 2016 11:28
-
-
Save kdnk/102ed7128c917a96bdbc0d490afbf69d 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
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