Skip to content
Browse files

Merge pull request #3 from amasad/master

Fixed off by one error.
  • Loading branch information...
2 parents 540cbc3 + 7206eab commit 575e6d5771709bb66ec28ebd42236c90b0d03f1d @amasad amasad committed Jan 3, 2014
Showing with 7 additions and 7 deletions.
  1. +5 −5 index.js
  2. +2 −2 test/history.js
View
10 index.js
@@ -56,7 +56,7 @@ History.prototype.max = function(n){
*/
History.prototype.add = function(val){
- this.i = this.vals.push(val) - 1;
+ this.i = this.vals.push(val);
this.cap();
return this;
};
@@ -69,8 +69,8 @@ History.prototype.add = function(val){
*/
History.prototype.prev = function(){
- if (this.i < 0) return;
- return this.vals[this.i--];
+ if (this.i <= 0) return;
+ return this.vals[--this.i];
};
/**
@@ -82,7 +82,7 @@ History.prototype.prev = function(){
History.prototype.next = function(){
var len = this.vals.length;
- if (this.i == len - 1) return;
+ if (this.i >= len) return;
return this.vals[++this.i];
};
@@ -94,6 +94,6 @@ History.prototype.next = function(){
*/
History.prototype.reset = function(){
- this.i = this.vals.length - 1;
+ this.i = this.vals.length;
return this;
};
View
4 test/history.js
@@ -56,7 +56,8 @@ describe('History', function(){
history.prev();
history.prev();
history.prev();
- history.next().should.equal('foo');
+ assert(!history.next());
+ history.prev().should.equal('foo');
})
})
@@ -69,7 +70,6 @@ describe('History', function(){
history.prev().should.equal('baz');
history.prev().should.equal('bar');
history.prev().should.equal('foo');
- history.next().should.equal('foo');
history.next().should.equal('bar');
history.next().should.equal('baz');
})

0 comments on commit 575e6d5

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