Skip to content

Instantly share code, notes, and snippets.

@williamlsh
Last active November 10, 2018 09:49
Show Gist options
  • Save williamlsh/909bea053c625cd0b6c694780431ec0a to your computer and use it in GitHub Desktop.
Save williamlsh/909bea053c625cd0b6c694780431ec0a to your computer and use it in GitHub Desktop.
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