Skip to content

Instantly share code, notes, and snippets.

@mu-hun
Last active May 21, 2020 13:20
Show Gist options
  • Select an option

  • Save mu-hun/8461c5bb8b51865ecd2d01d1199221bf to your computer and use it in GitHub Desktop.

Select an option

Save mu-hun/8461c5bb8b51865ecd2d01d1199221bf to your computer and use it in GitHub Desktop.
Implement fibonacci with Bottom-Up Style
function fib(n) {
let first = 1, second = 0;
let current;
for (let i = 2; i <= n; i++) {
current = first + second
second = first
first = current
}
return current
}
console.assert(fibonacciLoop(3) === 2);
console.assert(fibonacciLoop(4) === 3);
console.assert(fibonacciLoop(5) === 5);
console.assert(fibonacciLoop(6) === 8);
console.assert(fibonacciLoop(7) === 13);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment