{"ScriptPreparationCode":"var TestString = \u0027\u002B\u0027.repeat(200) \u002B \u0027=\u0027.repeat(20000) \u002B \u0027\u002B\u0027.repeat(200);\r\n\r\nfunction regexTrim(str, what) {\r\n const chars = [...(what ? what : \u0027\\0\\t\\n\\v\\r \u0027)].map((c) =\u003E ([\u0027]\u0027, \u0027^\u0027, \u0027\\\\\u0027, \u0027-\u0027].includes(c) ? \u0027\\\\\u0027 \u002B c : c)).join(\u0027\u0027);\r\n \r\n return str.replace(new RegExp(\u0027^[\u0027 \u002B chars \u002B \u0027]\u002B|[\u0027 \u002B chars \u002B \u0027]\u002B$\u0027, \u0027gu\u0027), \u0027\u0027);\r\n}\r\n\r\nfunction indexTrim(str, what) {\r\n let end, start;\r\n \r\n const chars = [...str];\r\n const charsToTrim = [...(what ? what : \u0027\\0\\t\\n\\v\\r \u0027)];\r\n \r\n start = 0;\r\n end = chars.length;\r\n\r\n while (start \u003C end \u0026\u0026 charsToTrim.includes(chars[start])) {\r\n \u002B\u002Bstart;\r\n }\r\n\r\n while (end \u003E start \u0026\u0026 charsToTrim.includes(chars[end - 1])) {\r\n --end;\r\n }\r\n\r\n return (start \u003E 0 || end \u003C chars.length) ? chars.slice(start, end).join(\u0027\u0027) : str.slice();\r\n}\r\n\r\nfunction booleanTrim(str, what) {\r\n let result;\r\n \r\n const chars = what ? what : \u0027\\0\\t\\n\\v\\r \u0027;\r\n \r\n result = str;\r\n for (const c of chars) {\r\n result = result.split(c).filter(Boolean).join(c);\r\n }\r\n \r\n return result;\r\n}\r\n\r\nfunction spreadTrim(str, what) {\r\n const chars = [...str];\r\n const charsToTrim = [...(what ? what : \u0027\\0\\t\\n\\v\\r \u0027)];\r\n const end = chars.reverse().findIndex((c) =\u003E !charsToTrim.includes(c));\r\n const start = chars.reverse().findIndex((c) =\u003E !charsToTrim.includes(c));\r\n \r\n return chars.slice(start, chars.length - end).join(\u0027\u0027);\r\n}\r\n\r\nfunction substringTrim(str, what) {\r\n const chars = what ? what : \u0027\\0\\t\\n\\v\\r \u0027;\r\n \r\n while (chars.includes(String.fromCodePoint(str.codePointAt(0)))) {\r\n str = str.substring(1);\r\n }\r\n\r\n while (chars.includes(String.fromCodePoint(str.codePointAt(str.length - 1)))) {\r\n str = str.substring(0, str.length - 1);\r\n }\r\n\r\n return str;\r\n}\r\n\r\nfunction sliceTrim(str, what) {\r\n const chars = what ? what : \u0027\\0\\t\\n\\v\\r \u0027;\r\n \r\n while (chars.includes(String.fromCodePoint(str.codePointAt(0)))) {\r\n str = str.slice(1);\r\n }\r\n\r\n while (chars.includes(String.fromCodePoint(str.codePointAt(str.length - 1)))) {\r\n str = str.slice(0, -1);\r\n }\r\n\r\n return str;\r\n}","TestCases":[{"Name":"Regex Trim","Code":"regexTrim(TestString, \u0027\u002B\u0027);","IsDeferred":false},{"Name":"Index Trim","Code":"indexTrim(TestString, \u0027\u002B\u0027)","IsDeferred":false},{"Name":"Boolean Filter Trim","Code":"booleanTrim(TestString, \u0027\u002B\u0027)","IsDeferred":false},{"Name":"Spread Trim","Code":"spreadTrim(TestString, \u0027\u002B\u0027)","IsDeferred":false},{"Name":"Substring Trim","Code":"substringTrim(TestString, \u0027\u002B\u0027)","IsDeferred":false},{"Name":"Slice Trim","Code":"sliceTrim(TestString, \u0027\u002B\u0027)","IsDeferred":false}]}