1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 1× 2× 2× 14× 8× 6× 6× 6× 2× 2× 1× 1× 1× 1× 1× 1× 1× 1× 2× 1× | 'use strict'; function calculate(...args) { let stack = []; args.forEach((arg) => { if (parseInt(arg)) { stack.push(arg); } else { const lhs = stack.pop(); const rhs = stack.pop(); switch (arg) { case '+': stack.push(rhs + lhs); break; case '-': stack.push(rhs - lhs); break; case '*': stack.push(rhs * lhs); break; case '/': stack.push(rhs / lhs); break; case '%': stack.push(rhs % lhs); break; } } }); return stack.pop(); } module.exports = calculate; |