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
27 stars 4 forks source link

91 - Stack - javascript #94

Open jsartisan opened 3 months ago

jsartisan commented 3 months ago

index.js

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

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

  peek() {
    return this.items.at(-1);
  }

  push(item) {
    return this.items.push(item);
  }

  pop() {
    return this.items.pop();
  }

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

export { Stack };