Last active
June 9, 2021 12:55
-
-
Save icantrank/5b1074f0236760dd04a0d93f9aafb895 to your computer and use it in GitHub Desktop.
Fibbonacier.js - Someone showed me a bad example of array restructuring yesterday. i thought this was prettier.
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
let Fibbonacier = function() { | |
let cache = [1,1] | |
let step = () => { | |
let nums = [...cache] | |
let [a,b] = [nums.pop() || 1, nums.pop() || 1] | |
cache.push(a+b) | |
} | |
return { | |
step : step, | |
result: cache | |
} | |
} | |
let fib = Fibbonacier() | |
fib.step() | |
fib.step() | |
fib.step() | |
fib.step() | |
fib.step() | |
fib.step() | |
console.log(fib.result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment