Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Digit Stack by ZoltanOnody
"use strict";
const digitStack = (commands) => {
let total = 0, stack = [];
for(let rawCommand of commands){
let [command, val] = rawCommand.split(' ');
if(command === 'PUSH'){
stack.push(Number(val));
} else if (command === 'POP'){
total += stack.pop() || 0;
} else {
total += stack[stack.length-1] || 0;
}
}
return total;
}
July 20, 2016
Comments: