Permalink
Browse files

Fixed off by one error.

  • Loading branch information...
1 parent 540cbc3 commit 7206eab4fcb2734f5b6ab9a0326710ff99bd619c @amasad amasad committed Dec 31, 2013
Showing with 7 additions and 7 deletions.
  1. +5 −5 index.js
  2. +2 −2 test/history.js
View
@@ -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
@@ -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 7206eab

Please sign in to comment.