class Stack extends Array {
constructor (size = 10, ...values) {
super(...values)
this.size = size;
}
isEmpty() {
return this.length == 0;
}
isFull() {
return this.length == this.size;
}
add(item) {
if (this.isFull()) {
throw 'Stack Overflow'
} else {
this.push(item);
}
}
remove() {
if (this.isEmpty()) {
throw 'Stack Underflow';
} else {
this.pop();
}
}
}