jsartisan / frontend-challenges

FrontendChallenges is a collection of frontend interview questions and answers. It is designed to help you prepare for frontend interviews. It's free and open source.
https://frontend-challenges.com
20 stars 3 forks source link

95 - Queue - javascript #98

Open jsartisan opened 1 week ago

jsartisan commented 1 week ago

index.js

class Queue {
  constructor() {
    this.items = [];
  }

  enqueue(element) {
    this.items.push(element);
  }

  dequeue() {
    return this.items.shift();
  }

  front() {
    return this.items[0];
  }

  isEmpty() {
    return this.size() == 0;
  }

  size() {
    return this.items.length;
  }
}

export { Queue };