Quick actions

cmd+k|ctrl+k

Navigation

Languages

Stack : Array 

Snippet info

Language

JavaScript

Visibility

public

Author

kishorrathva8298

Created

2022-04-08T15:11:13.945191Z

Updated

2022-04-08T15:11:13.945191Z

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

  peek() {
    return this.array[this.array.length - 1];
  }
  push(value) {
    this.array.push(value);
  }
  pop() {
    this.array.pop();
    return this;
  }
}

const stack = new Stack();
stack.push(10);
stack.push(12);
stack.push(11);
stack.push(14);
stack.pop();
stack.pop();
stack.pop();
// stack.pop();
stack.pop();
// stack.pop();
// stack.pop();

console.log(stack.pop());
INFO