var simplifyPath = function(path) { let stack = path.split('/') let res = [] for(let p of stack) { if(p === '..') { res.pop() } else if( p && p !== '.') { res.push(p) } } return '/'+res.join('/')};
var evalRPN = function (tokens) { const stack = [] const ops = { '+': (a, b) => a + b, '-': (a, b) => a - b, '*': (a, b) => a * b, '/': (a, b) => ~~(a / b) // 向零取整 } for (const t of tokens) { if (t in ops) { const b = stack.pop() const a = stack.pop() stack.push(ops[t](a, b)) } else { stack.push(Number(t)) } } return stack[0]};
var calculate = function(s) { let result = 0 let num = 0 let sign = 1 const stack = [] for (const c of s) { if (c >= '0' && c <= '9') { num = num * 10 + Number(c) } else if (c === '+' || c === '-') { result += sign * num num = 0 sign = c === '+' ? 1 : -1 } else if (c === '(') { stack.push(result) stack.push(sign) result = 0 sign = 1 } else if (c === ')') { result += sign * num num = 0 result *= stack.pop() // sign result += stack.pop() // prev result } } return result + sign * num}