{"ScriptPreparationCode":"var TestString = \u0027\u002B\u0027.repeat(200) \u002B \u0027=\u0027.repeat(20000) \u002B \u0027\u002B\u0027.repeat(200);\r\n\r\nvar regexTrim = function(str, ch) {\r\n if (ch === \u0027]\u0027) ch = \u0027\\\\]\u0027;\r\n else if (ch === \u0027^\u0027) ch = \u0027\\\\^\u0027;\r\n else if (ch === \u0027\\\\\u0027) ch = \u0027\\\\\\\\\u0027;\r\n return str.replace(new RegExp(\u0027^[\u0027 \u002B ch \u002B \u0027]\u002B|[\u0027 \u002B ch \u002B \u0027]\u002B$\u0027, \u0027g\u0027), \u0027\u0027);\r\n};\r\n\r\nfunction indexTrimSet(str, ch) {\r\n\tch=new Set(ch);\t\r\n\tfor(var end=str.length-1 ; end\u003E=0 \u0026\u0026 ch.has(str[end ]) ; --end );\r\n\tfor(var start=0 ; start\u003Cend \u0026\u0026 ch.has(str[start]) ; \u002B\u002Bstart );\r\n\treturn (start \u003E 0 || end \u003C str.length-1) ? str.substring(start, end\u002B1) : str;\r\n}\r\n\r\nfunction indexTrim(str, ch) {\r\n var start = 0, \r\n end = str.length;\r\n\r\n while(start \u003C end \u0026\u0026 str[start] === ch)\r\n \u002B\u002Bstart;\r\n\r\n while(end \u003E start \u0026\u0026 str[end - 1] === ch)\r\n --end;\r\n\r\n return (start \u003E 0 || end \u003C str.length) ? str.substring(start, end) : str;\r\n}\r\n\r\nfunction booleanTrim(str, ch) {\r\n return str.split(ch).filter(Boolean).join(ch);\r\n}\r\n\r\nfunction spreadTrim(str, ch) {\r\n const first = [...str].findIndex(char =\u003E char !== ch);\r\n const last = [...str].reverse().findIndex(char =\u003E char !== ch);\r\n return str.substring(first, str.length - last);\r\n}\r\n\r\nfunction substringTrim(str, ch) {\r\n while(str.charAt(0)==ch) {\r\n str = str.substring(1);\r\n }\r\n\r\n while(str.charAt(str.length-1)==ch) {\r\n str = str.substring(0,str.length-1);\r\n }\r\n\r\n return str;\r\n}","TestCases":[{"Name":"Index Version (Jason Larke)","Code":"indexTrim(TestString, \u0027\u002B\u0027);","IsDeferred":false},{"Name":"Regex Version (leaf)","Code":"regexTrim(TestString, \u0027\u002B\u0027)","IsDeferred":false},{"Name":"Boolean Filter Version (mbaer3000)","Code":"booleanTrim(TestString, \u0027\u002B\u0027)","IsDeferred":false},{"Name":"Spread Version (Robin F.)","Code":"spreadTrim(TestString, \u0027\u002B\u0027)","IsDeferred":false},{"Name":"Substring Version (Pho3niX83)","Code":"substringTrim(TestString, \u0027\u002B\u0027)","IsDeferred":false},{"Name":"set version of indexTrim optimized for trimming many different characters","Code":"indexTrimSet(TestString, \u0027\u002B\u0027)","IsDeferred":false}]}