AniUI Academy
easy+150 XPPractice

A queue for work that must happen in order

Anything that must happen in the order it was asked for goes through a queue: uploads waiting on a connection, toasts waiting for the one on screen to expire, events buffered while the socket reconnects.

Implement a Queue class. It is constructed with no arguments and starts empty. enqueue(value) adds a value to the back and returns the new size as a number. dequeue() removes the value at the front and returns it, or returns undefined when the queue is empty. front() returns the front value without removing it, or undefined when the queue is empty. size() returns how many values are held. isEmpty() returns true when nothing is held and false otherwise.

What it has to do

  • dequeue returns values in the order they were enqueued.
  • enqueue returns the size of the queue after the value was added.
  • dequeue and front return undefined on an empty queue rather than throwing.
  • front leaves the queue unchanged.
  • Enqueueing after the queue has drained works normally.

Your workspace

Try it yourself
Loading playground...

Ready to check it?

5 tests run against your code, right here in your browser. Sign in to claim the XP when you pass.

AI Crack & Solution Assist

Stuck? Get instant AI hints or break down the optimal solution.

Stuck? The javascript course covers everything this challenge needs.