{"ScriptPreparationCode":"var paths = [];\r\n\r\nfunction nthIndexOf(s, search, count, pos = 0) {\r\n let i = pos - 1;\r\n while (count \u003E 0) {\r\n i = s.indexOf(search, i \u002B 1);\r\n if (i === -1) {\r\n break;\r\n }\r\n count--;\r\n }\r\n return i;\r\n}\r\n\r\nfunction nthIndexOfRec(s, search, count, pos = 0) {\r\n const recurse = (c, p) =\u003E {\r\n if (c === 0) {\r\n return p;\r\n }\r\n const index = s.indexOf(search, p \u002B 1);\r\n if (index === -1) {\r\n return -1;\r\n }\r\n return recurse(c - 1, index);\r\n };\r\n return recurse(count, pos - 1);\r\n}\r\n\r\nfunction nthIndexOfCc(s, search, count, pos = 0) {\r\n const recurse = (c, p, cc) =\u003E {\r\n if (c === 0) {\r\n cc(p);\r\n return;\r\n }\r\n const index = s.indexOf(search, p \u002B 1);\r\n if (index === -1) {\r\n cc(-1);\r\n return;\r\n }\r\n recurse(c - 1, index, cc);\r\n };\r\n\r\n let result = -1;\r\n recurse(count, pos - 1, n =\u003E (result = n));\r\n return result;\r\n}","TestCases":[{"Name":"while","Code":"paths.forEach(path =\u003E console.log(path.substring(0, nthIndexOf(path, \u0027/\u0027, 5) \u002B 1)));","IsDeferred":false},{"Name":"recurse","Code":"paths.forEach(path =\u003E console.log(path.substring(0, nthIndexRec(path, \u0027/\u0027, 5) \u002B 1)));","IsDeferred":false},{"Name":"continuation","Code":"paths.forEach(path =\u003E console.log(path.substring(0, nthIndexCc(path, \u0027/\u0027, 5) \u002B 1)));","IsDeferred":false}]}