Skip to content

Instantly share code, notes, and snippets.

@JordanMajd
Created April 6, 2016 21:50
Show Gist options
  • Save JordanMajd/bf3e7dd442640b5bcffe3ce8b4babd18 to your computer and use it in GitHub Desktop.
Save JordanMajd/bf3e7dd442640b5bcffe3ce8b4babd18 to your computer and use it in GitHub Desktop.
'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