MCPcopy Index your code
hub / github.com/neetcode-gh/leetcode / evalRPN

Function evalRPN

javascript/0150-evaluate-reverse-polish-notation.js:7–21  ·  view source on GitHub ↗
(tokens, index = 0)

Source from the content-addressed store, hash-verified

5 * @return {number}
6 */
7var 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
23var OPERATORS = {
24 '+': (a, b) => a + b,

Callers

nothing calls this directly

Calls 4

isOperationFunction · 0.85
performOperationFunction · 0.85
pushMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected