Skip to content

Commit 6619062

Browse files
authored
Update queue.js
1 parent 27f397a commit 6619062

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

queue.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,36 @@ function Queue() {
44
this.items = [];
55
}
66

7+
// Add/remove items from the begining of the array
8+
9+
function Queue() {
10+
this.items = [...arguments];
11+
}
12+
713
Queue.prototype = {
814
constructor: Queue,
9-
add: function add(item) {
10-
this.items.push(item);
15+
add: function() {
16+
this.items.push(...arguments);
1117
return this;
1218
},
13-
remove: function remove() {
19+
remove: function() {
1420
this.items.shift();
1521
return this;
1622
},
17-
get: function get() {
23+
get: function() {
1824
return this.items;
1925
}
20-
};
26+
}
27+
28+
const myQueue = new Queue(1, 2, 3, 4);
29+
30+
console.log(myQueue.get()); // [ 1, 2, 3, 4 ]
31+
32+
myQueue.add(5, 6);
33+
34+
console.log(myQueue.get()); // [ 1, 2, 3, 4, 5, 6 ]
2135

22-
var myQueue = new Queue();
23-
myQueue.add(100).add(23).add(12).add(78);
2436
myQueue.remove();
25-
console.log(myQueue.get());
37+
38+
console.log(myQueue.get()); // [ 2, 3, 4, 5, 6 ]
39+

0 commit comments

Comments
 (0)