DEV Community

Discussion on: Stacks vs. Queues In JavaScript

Collapse
 
danielsan profile image
Daniel Santana

A slightly faster alternative for the queue would be this:

enqueue(item) { return queue.push(item); }
dequeue() { return queue.shift(); }
peek() { return queue[0]; } // no need to calculate the length of the array or any math ;)