From b68f75284754c4847958d661f1bf98fd6d064ed8 Mon Sep 17 00:00:00 2001 From: Prashanth Ashok Ramkumar Date: Tue, 2 Jul 2019 10:45:42 -0400 Subject: [PATCH] Adding solution for queue class (#36319) --- .../create-a-queue-class.english.md | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/curriculum/challenges/english/08-coding-interview-prep/data-structures/create-a-queue-class.english.md b/curriculum/challenges/english/08-coding-interview-prep/data-structures/create-a-queue-class.english.md index 32e18427ef..e701563fd2 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/data-structures/create-a-queue-class.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/data-structures/create-a-queue-class.english.md @@ -68,6 +68,32 @@ function Queue() {
```js -// solution required +function Queue () { + var collection = []; + this.print = function() { + console.log(collection); + }; + // Only change code below this line + this.enqueue = function(item) { + collection.push(item); + } + + this.dequeue = function() { + return collection.shift(); + } + + this.front = function() { + return collection[0]; + } + + this.size = function(){ + return collection.length; + } + + this.isEmpty = function() { + return collection.length === 0 ? true : false; + } + // Only change code above this line +} ```