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

Function calPoints

javascript/0682-baseball-game.js:5–29  ·  view source on GitHub ↗
(operations)

Source from the content-addressed store, hash-verified

3 * @return {number}
4 */
5var calPoints = function(operations) {
6 let runningSum = 0;
7 const stack = [];
8 for(const o of operations) {
9 if(o === 'C') {
10 runningSum -= stack.pop();
11 continue;
12 }
13 if(o === 'D') {
14 const val = stack[stack.length - 1] * 2;
15 stack.push(val);
16 runningSum += val;
17 continue;
18 }
19 if(o === '+') {
20 const val = stack[stack.length - 1] + stack[stack.length - 2];
21 stack.push(val);
22 runningSum += val;
23 continue;
24 }
25 stack.push(+o);
26 runningSum += +o;
27 }
28 return runningSum;
29};

Callers

nothing calls this directly

Calls 2

popMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected