Skip to content

Instantly share code, notes, and snippets.

@andrit
Last active December 14, 2018 04:14
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 andrit/3eae439881f8b3e9a1265d5d5c940aa7 to your computer and use it in GitHub Desktop.
Save andrit/3eae439881f8b3e9a1265d5d5c940aa7 to your computer and use it in GitHub Desktop.
//export default createQueue = () => { //need static
function createQueue(){
	//cache
	//Private
	const queue = [];
	//Revealing Module Pattern
	return {
		enqueue(item) {
			queue.unshift(item);
		},
		dequeue() {
			return queue.pop();
		},
		peek() { return queue[queue.length - 1]},
		get length() { return queue.length},
		isEmpty() { return queue.length === 0}


	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment