Mini Parser LeetCode solution in JavaScript
1var deserialize = function (s) {2if (s[0] !== "[") return new NestedInteger(s);34const stack = [];5let start = 0;6const process = {7"["(index) {8stack.push(new NestedInteger());9start = index + 1;10},11","(index) {12if (index > start) {13const value = s.slice(start, index);14stack[stack.length - 1].add(new NestedInteger(value));15}16start = index + 1;17},18"]"(index) {19this[","](index);20if (stack.length < 2) return;21const last = stack.pop();22stack[stack.length - 1].add(last);23},24};2526[...s].forEach((current, index) => process[current]?.(index));2728return stack[0];29};