Skip to content

Instantly share code, notes, and snippets.

@abacaj
Created November 16, 2015 15:58
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 abacaj/e0ea9028e12ef597676e to your computer and use it in GitHub Desktop.
Save abacaj/e0ea9028e12ef597676e to your computer and use it in GitHub Desktop.
A simple implementation of fibonacci in javascript.
function fibonacci(size) {
var first = 0,
second = 1,
next,
count = 2,
result = [first, second];
if(size < 2) {
console.log(result);
return;
}
while(count++ < size) {
next = first + second;
first = second;
second = next;
result.push(next);
}
console.log(result);
}
fibonacci(5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment