Skip to content

Instantly share code, notes, and snippets.

@shawndumas
Created September 30, 2011 20:43
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 shawndumas/1254921 to your computer and use it in GitHub Desktop.
Save shawndumas/1254921 to your computer and use it in GitHub Desktop.
Next Fibonacci
var r = [],
n = 0,
a = 0,
b = 1,
next;
function nextFibonacci() {
next = a + b;
return b = (a = b, next);
}
while(n++ < 10) {
r.push(nextFibonacci());
}
r; //[1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment