{"ScriptPreparationCode":"var xpath = \u0022sdf[ewr[da[[[s]]]df[[[d]]]saf]a[[[s]]]d[[[fa]]]s[[[[[[[[[df]gh[asdf]]]]]]]]]asdf]adsdasd[asd[[[a]]]sd]as[[[[[[dasd]]]]]]sa[asd[[[[[asdasdasd]]]]]asd]\u0022","TestCases":[{"Name":"Reduce","Code":"var result = _.reduce(xpath, function(accumulator, element, index) {\r\n if (element === \u0027[\u0027) {\r\n accumulator.push({start: index});\r\n\t}\r\n\tif (element === \u0027]\u0027) {\r\n\t\t_.set(_.findLast(accumulator, (obj) =\u003E !obj.end), \u0022end\u0022, index);\r\n }\r\n return accumulator;\r\n}, []);","IsDeferred":false},{"Name":"For","Code":"var predicateMarkStack = [];\r\nvar predicateMarkIndexRange = [];\r\nfor (var i = 0; i \u003C xpath.length; i\u002B\u002B) {\r\n if (xpath.charAt(i) === \u0022[\u0022) {\r\n predicateMarkStack.push(i);\r\n }\r\n if (xpath.charAt(i) === \u0022]\u0022) {\r\n var index = predicateMarkStack.pop();\r\n predicateMarkIndexRange.push({init: index, end: i});\r\n }\r\n}","IsDeferred":false},{"Name":"Reduce (ignoring nested)","Code":"var array = []\r\nvar result = _.reduce(xpath, function(accumulator, element, index) {\r\n if (element === \u0027[\u0027) {\r\n array.push(index);\r\n\t}\r\n\tif (element === \u0027]\u0027) {\r\n\t\tvar startIndex = array.pop()\r\n\t\tif (array.length === 0) {\r\n\t\t\taccumulator.push({ start: startIndex, end: index})\r\n\t\t}\t\t\r\n }\r\n return accumulator;\r\n}, []);","IsDeferred":false},{"Name":"For (ignoring nested)","Code":"var predicateMarkStack = [];\r\nvar predicateMarkIndexRange = [];\r\nfor (var i = 0; i \u003C xpath.length; i\u002B\u002B) {\r\n if (xpath.charAt(i) === \u0022[\u0022) {\r\n predicateMarkStack.push(i);\r\n }\r\n if (xpath.charAt(i) === \u0022]\u0022) {\r\n var index = predicateMarkStack.pop();\r\n if (predicateMarkStack.length === 0) {\r\n predicateMarkIndexRange.push({init: index, end: i});\r\n }\r\n }\r\n}","IsDeferred":false},{"Name":"Reduce with pop","Code":"var array = []\r\nvar result = _.reduce(xpath, function(accumulator, element, index) {\r\n if (element === \u0027[\u0027) {\r\n array.push(index);\r\n\t}\r\n\tif (element === \u0027]\u0027) {\r\n\t\tvar startIndex = array.pop()\t\t\r\n accumulator.push({ start: startIndex, end: index})\t\t\r\n }\r\n return accumulator;\r\n}, []);","IsDeferred":false}]}