I have done as the instructions asked and I used the push method to add an element to the back of the queue and returned it, removed the return keyword, logged and tested it to the console and it worked fine but after all tries, the test doe’nt pass. Samething with the dequeue function. Somebody please explain what I am missing please. I also intentionally added the elements to the collection after trying while it’s empty and it did not change anything
Your code so far
function initQueue() {
return {
collection: ['cat', 'fish']
};
}
function print(queue) {
console.log(queue.collection);
}
function enqueue(queue, element) {
queue.collection.push(element);
return queue.collection;
}
//Test working properly but refusing to pass
const myQueue = initQueue();
console.log(enqueue(myQueue, "Dog"));
function dequeue(queue) {
return queue.collection.shift()
}
console.log(dequeue(myQueue));
function front(queue) {
}
function size(queue) {
}
function isEmpty(queue) {
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Hello, I’ve run into a similar problem last night, but just found this last message. Has the enqueue test been fixed? Or should I complete the size and front methods first in the meantime?
Edit: turns out that filling in the size and front methods with the correct logic ends up checking out Chivorofiel’s logic so far.