Created
April 6, 2016 21:50
-
-
Save JordanMajd/bf3e7dd442640b5bcffe3ce8b4babd18 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
'use strict'; | |
// Queue constructor | |
// properties: | |
// values: some way of storing data. | |
const Queue = function(){ | |
// create the values property and assign it the value of an array literal. | |
this.values = []; | |
}; | |
// remove | |
// description: | |
// removes and returns the value at the front of the Queue. | |
// returns: | |
// the removed value. | |
Queue.prototype.remove = function(){ | |
//if you push() to add values use shift() to remove them. | |
return this.values.shift(); | |
//if you unshift() to add values use pop() to remove them. | |
//return this.values.pop(); | |
}; | |
// add | |
// parameters: | |
// value: the data to add to the Queue. | |
// description: | |
// adds the value to the back of the Queue. | |
Queue.prototype.add = function(value){ | |
//if you shift() values off, use push() to add values to the Queue. | |
this.values.push(value); | |
//if you pop() values off, use unshift() to add values to the Queue. | |
// this.values.unshift(); | |
}; | |
// peek | |
// description: | |
// returns the value at the front of the Queue | |
Queue.prototype.peek = function(){ | |
//if you shift/push, show the last element in the array: | |
return this.values[0]; | |
//if you unshift/pop, show the first element in the array: | |
//return this.values[this.values.length - 1]; | |
}; | |
// isEmpty | |
// description: | |
// returns true if the Queue has no data in it | |
Queue.prototype.isEmpty = function(){ | |
return this.values.length === 0; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment