Created
November 16, 2015 15:58
-
-
Save abacaj/e0ea9028e12ef597676e to your computer and use it in GitHub Desktop.
A simple implementation of fibonacci in javascript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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