Created
January 18, 2014 06:44
-
-
Save sethkontny/8487099 to your computer and use it in GitHub Desktop.
A Fibonacci sequence generator written in JavaScript (Node.JS).
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 (upto) { | |
if(upto.length == 0) { | |
console.log("Usage: fibonacci <upto>."); | |
} else { | |
var first = 0, second = 1, sum; | |
var fibonacci_string = ""; | |
fibonacci_string += (first + " " + second); | |
for (var counter = 0; counter < (upto - 2); counter++) { | |
sum = first + second; | |
fibonacci_string += (" " + sum); | |
first = second; | |
second = sum; | |
}; | |
console.log(fibonacci_string); | |
} | |
} | |
fibonacci(process.argv.splice(2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Go for the latest revision.
https://gist.github.com/mayureshkathe/8486955/7cd86d9c1fc8c68db12223b7a9299c35dbcdee5a