Created
August 19, 2013 09:03
-
-
Save jineeshjohn/6267081 to your computer and use it in GitHub Desktop.
fibonacci in JavaScript with iterative approach
This file contains hidden or 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 fibo(n) { | |
var f = []; | |
for (var i = 0; i < n; i++ ) { | |
var item = (i < 2) ? i : f[i-1] + f[i-2]; | |
f.push(item); | |
} | |
return f; | |
} | |
var fibos = fibo(5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment