(tokens, index = 0)
| 5 | * @return {number} |
| 6 | */ |
| 7 | var evalRPN = function (tokens, index = 0) { |
| 8 | while (1 < tokens.length) { |
| 9 | /* Time O(N) */ |
| 10 | const isOperation = () => tokens[index] in OPERATORS; |
| 11 | while (!isOperation()) index++; /* Time O(N) */ |
| 12 | |
| 13 | const value = performOperation(tokens, index); |
| 14 | |
| 15 | tokens[index] = value; |
| 16 | tokens.splice(index - 2, 2); /* Time O(N) */ |
| 17 | index--; |
| 18 | } |
| 19 | |
| 20 | return tokens[0]; |
| 21 | }; |
| 22 | |
| 23 | var OPERATORS = { |
| 24 | '+': (a, b) => a + b, |
nothing calls this directly
no test coverage detected