Created
December 10, 2009 00:08
-
-
Save howardr/252976 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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