Skip to content

Instantly share code, notes, and snippets.

@niczky12
Last active May 27, 2020 19:39
Show Gist options
  • Save niczky12/e3834acb82cf92ee39da478151735861 to your computer and use it in GitHub Desktop.
Save niczky12/e3834acb82cf92ee39da478151735861 to your computer and use it in GitHub Desktop.
Fibonacci in JS
function fib(n) {
var numbers = [0, 1] // initialise the array
while (n > 1) {
var new_num = numbers[0] + numbers[1];
numbers.shift(); // drop the first element
numbers.push(new_num); // add the new element to the end
n -= 1;
}
return numbers[n];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment