stack.js

For all your stack-based programming needs, a very minimal class to implement a stack in javascript.

class Stack {
  items = []
  push = (element) => this.items.push(element)
  pop = () => this.items.pop()
  isempty = () => this.items.length === 0
  empty = () => (this.items.length = 0)
  size = () => this.items.length
}

// example usage
const stack = new Stack()
stack.push(2)
console.log(stack.items) // => 2

Is this useful or even the best implementation of this? Very very doubtful…