Last active
November 10, 2018 09:49
-
-
Save williamlsh/909bea053c625cd0b6c694780431ec0a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function fabonacci() { | |
let fabonacciArray = [1, 1]; | |
let fn; | |
return function cur() { | |
const len = fabonacciArray.length; | |
fn = fabonacciArray.slice(len - 2, len).reduce((pre, cur) => pre + cur); | |
fabonacciArray.push(fn); | |
console.log(fabonacciArray); | |
return fn; | |
}; | |
} | |
const cur = fabonacci(); | |
for (let i = 0; i < 10; i++) { | |
console.log(cur()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment