Adding solution for queue class (#36319)
This commit is contained in:
committed by
Randell Dawson
parent
d118e199c5
commit
b68f752847
@ -68,6 +68,32 @@ function Queue() {
|
|||||||
<section id='solution'>
|
<section id='solution'>
|
||||||
|
|
||||||
```js
|
```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
|
||||||
|
}
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
Reference in New Issue
Block a user