Skip to content

Instantly share code, notes, and snippets.

@icantrank
Last active June 9, 2021 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icantrank/5b1074f0236760dd04a0d93f9aafb895 to your computer and use it in GitHub Desktop.
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.
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