Skip to content
Browse files

Bug fixed: the first loop was skipped

  • Loading branch information...
1 parent c447c76 commit a12c37d484573c7d96ac244f7303234e55d2384f @fvdm committed May 15, 2012
Showing with 10 additions and 7 deletions.
  1. +9 −6 fibonacci.js
  2. +1 −1 package.json
View
15 fibonacci.js
@@ -3,7 +3,7 @@ This file is copyleft.
You can do whatever you want, just don't copyright it.
Source: https://github.com/fvdm/nodejs-fibonacci
-Update: 2012-05-15T14:54:00+0100
+Update: 2012-05-15T15:23:00+0100
Description:
This function calculates fibonacci numbers for one or endless iterations.
@@ -42,17 +42,17 @@ var app = new EventEmitter();
app.iterate = function( limit ) {
var next = bignum(1),
+ cur = bignum(-1),
last = bignum(0),
- loop = bignum(1),
+ loop = bignum(0),
start = new Date().getTime();
app.doWhile = true;
while( app.doWhile ) {
- loop = loop.add(1);
- cur = last;
- last = next;
- next = next.add(cur);
+ last = cur; // prev cur -> now last
+ cur = next; // prev next -> now cur
+ next = cur.add(last);
var result = {
number: next.toString(),
@@ -82,6 +82,9 @@ app.iterate = function( limit ) {
});
break;
}
+
+ // count
+ loop = loop.add(1);
}
}
View
2 package.json
@@ -2,7 +2,7 @@
"author": "Franklin van de Meent <fr@nkl.in> (http://frankl.in)",
"name": "fibonacci",
"description": "Calculates fibonacci numbers for one or endless iterations. Using the bignum module, it can return numbers of any size! Instead of being limited by the hardcoded JavaScript Number.MAX_LIMIT.",
- "version": "1.2.0",
+ "version": "1.2.1",
"homepage": "https://github.com/fvdm/nodejs-fibonacci",
"repository": {
"type": "git",

0 comments on commit a12c37d

Please sign in to comment.
Something went wrong with that request. Please try again.