Skip to content

Instantly share code, notes, and snippets.

@satoshun
Created March 23, 2013 05:48
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 satoshun/5226623 to your computer and use it in GitHub Desktop.
Save satoshun/5226623 to your computer and use it in GitHub Desktop.
test iterator
describe('iterator', function() {
it('test', function() {
var Iter = function(data){
this.index = 0;
this.data = data;
};
Iter.prototype = {
next: function(){
var elem = this.data[this.index];
this.index += 1;
return elem;
},
hasNext: function(){
return this.index < this.data.length;
},
seek: function(reindex){
this.index = reindex;
}
};
var data = [1, 2, 3, 4, 5];
var iter = new Iter(data);
while(iter.hasNext()){
console.log(iter.next());
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment