Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
"Digit Stack" solution in Clear category for [old] Digit Stack by capback250
"use strict";
class Stack {
constructor() {
this.q = [];
}
set PUSH(n) {
this.q.push(n)
}
get POP() {
return this.q.length ? this.q.pop() : 0
}
get PEEK() {
return this.q.length ? this.q[this.q.length -1] : 0
}
}
function digitStack(commands, sum=0) {
let s = new Stack();
commands.map(com=>{
let [c,n] = com.split(' ');
n ? s[c] = n : sum += +s[c]
});
return sum;
}
May 16, 2017