{"ScriptPreparationCode":"string = \u0022some string with values in it and other value and many more values and we want to replace some strings in it\u0022\r\nconst replace = { \u0027value\u0027: \u0027X\u0027, \u0027and\u0027: \u0027or\u0027, \u0027string\u0027: \u0027number\u0027 }\r\nconst expected = \u0027some number with Xs in it or other X or many more Xs or we want to replace some numbers in it\u0027\r\n\r\nconst re = /value|and|string/g\r\nconst re_replace = (s) =\u003E replace[s]\r\nre_replace_all = (input) =\u003E input.replace(re, re_replace)\r\n\r\ns_replace_all = (input) =\u003E {\r\n let result = input\r\n for (let from in replace) {\r\n result = s_replace(result, from, replace[from])\r\n }\r\n return result\r\n}\r\n\r\nconst s_replace = (input, from, to) =\u003E {\r\n let start = \u0027\u0027\r\n let end = input\r\n let index = end.indexOf(from)\r\n while (index !== -1) {\r\n start \u002B= end.substring(0, index) \u002B to\r\n end = end.substring(index \u002B from.length)\r\n index = end.indexOf(from)\r\n }\r\n return start \u002B end\r\n}\r\n\r\ns_replace_all2 = (input) =\u003E {\r\n let result = input\r\n for (let from in replace) {\r\n result = result.split(from).join(replace[from])\r\n }\r\n return result\r\n}\r\n\r\n\r\nconst assertEqual = (x, y) =\u003E {\r\n if (x !== y) throw new Error(\u0027nope\u0027)\r\n}\r\nassertEqual(re_replace_all(string), expected)\r\nassertEqual(s_replace_all(string), expected)\r\nassertEqual(s_replace_all2(string), expected)","TestCases":[{"Name":"using regexp","Code":"re_replace_all(string)","IsDeferred":false},{"Name":"using indexOf \u002B substring","Code":"s_replace_all(string)","IsDeferred":false},{"Name":"using split \u002B join","Code":"s_replace_all2(string)","IsDeferred":false}]}