Write a function named createQueue
that returns an Object that behaves like a queue.
The Object should have 3 properties which are all functions:
add
- a function that takes a parameter and adds it to the queueremove
- a function that removes the oldest item from the queue and returns itlist
- a function that returns all items from the queue as an Array. The order should be the same as the order in which they were added to the queue.const queue = createQueue();
queue.add(1);
queue.add(2);
queue.add(3);
console.log(queue.list()); // should print [1, 2, 3]
queue.remove();
console.log(queue.list()); // should print [2, 3]
queue.remove();
console.log(queue.list()); // should print [3]
queue.remove();
console.log(queue.list()); // should print []