Skip to content

Instantly share code, notes, and snippets.

@icantrank
Last active June 9, 2021 12:55
Embed
What would you like to do?
Fibbonacier.js - Someone showed me a bad example of array restructuring yesterday. i thought this was prettier.
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