Skip to content

Instantly share code, notes, and snippets.

@howardr
Created December 10, 2009 00:08
Show Gist options
  • Save howardr/252976 to your computer and use it in GitHub Desktop.
Save howardr/252976 to your computer and use it in GitHub Desktop.
// faster dequeue
// uses and array as prototype so all array methods are available.
// "unshift" has method overridden to not re-size the array
//
// var queue = new Queue();
function Queue() {
this._i = 0;
}
Queue.prototype = [];
Queue.prototype.unshift = function() {
var i = this._i;
if(i < this.length) {
var val = this[this._i];
this[this._i] = null;
this._i++;
return val;
}
else {
return null;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment