Implement a Queue - Implement a Queue

Tell us what’s happening:

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

Challenge Information:

Implement a Queue - Implement a Queue

Hi @Chirovofiel,

Please review the area about Queues in this theory lecture:

Working with Common Data Structures - How Do Stacks and Queues Work? | Learn | freeCodeCamp.org

Happy coding!

I did and I have implemented what I understood. Did you read my code sir? Am I getting all the logic wrong or what

Yes, your understanding of the front and back of the queue seems to be incorrect.

I opened an fCC issue as the test for enqueue requires that the size and front methods be completed first.

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.

Thank you.