Skip to content

Instantly share code, notes, and snippets.

@thinklinux
Created August 22, 2015 18:47
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 thinklinux/6808ac6a94cbe3cd2e97 to your computer and use it in GitHub Desktop.
Save thinklinux/6808ac6a94cbe3cd2e97 to your computer and use it in GitHub Desktop.
Fibonacci with javascript
// start should be 0 or 1 because by definition fibonacci sequence is starting from 0 element with 0,1 or from the first element with 1,1
var start = 0// or 1;
var results = start == 0 ? [0, 1] : [1, 1];
var i = 0;
var end = 10; // how far you want to go
while(i < end) {
var len = results.length;
var next = results[len-1] + results[len-2];
results.push(next);
i = i + 1;
}
console.log(results.join(', '));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment