Skip to content

Instantly share code, notes, and snippets.

@kaplan81
Last active January 10, 2016 17:56
Show Gist options
  • Save kaplan81/98680fe4370c52294a09 to your computer and use it in GitHub Desktop.
Save kaplan81/98680fe4370c52294a09 to your computer and use it in GitHub Desktop.
Fibonacci Series
function fibonacci(size) {
var result = [0];
var counter;
for (counter = 1; counter < size; counter++) {
result[counter] = (result[counter-1] || 1) + result[Math.max(0, counter-2)];
}
return result;
}
// fibonacci(8) returns [ 0, 1, 1, 2, 3, 5, 8, 13 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment