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 mozurin
"use strict";
function digitStack(commands)
{
return commands.reduce(
([stack, sum], cline) => {
const [cmd, operand] = cline.split(' ');
({
PUSH: (n => stack.unshift(parseInt(n))),
POP: () => sum += stack.shift() || 0,
PEEK: () => sum += stack[0] || 0,
})[cmd](operand);
return [stack, sum];
},
[[], 0]
)[1];
}
June 25, 2018
Comments: