var evalRPN = function(tokens) { if (tokens.length === 1) return +tokens[0]; const stack = []; const operations = new Set(['+', '-', '*', '/']); function calc(left, right, sign) { switch (sign) { case '+': return left + right case '-': return left - right case '*': return left * right case '/': { const result = left / right; return result < 0 ? Math.ceil(result) : Math.floor(result); } } } for (const token of tokens) { if (!operations.has(token)) { stack.push(+token); } else { const right = stack.pop(); const left = stack.pop(); const value = calc(left, right, token); stack.push(value); } } return stack.pop();};