function TripleStack() {
this._array = [];
this._lengths = [0, 0, 0];
}
TripleStack.prototype._getLength = function(stack) {
return this._lengths[stack-1];
};
TripleStack.prototype.push = function(stack, val){
const idx = this._getLength(stack) * 3 + stack - 1;
this._array[idx] = val;
this._lengths[stack - 1]++;
};
TripleStack.prototype.pop = function(stack) {
let len = this._getLength(stack);
let val;
if (len) {
const idx = (len - 1) * 3 + stack - 1;
val = this._array[idx];
delete this._array[idx];
this._lengths[stack - 1]--;
}
return val;
};
TripleStack.prototype.peek = function(stack) {
let len = this._getLength(stack);
let val;
if (len) {
const idx = (len - 1) * 3 + stack - 1;
val = this._array[idx];
}
return val;
};
TripleStack.prototype.isEmpty = function(stack) {
return this._getLength(stack) === 0;
};