{"ScriptPreparationCode":"var rawText = \u0027Lorem ipsum dolor sit amet, consectetur adipiscing elit, \u003C!--sed do \u003C/style\u003Eeiusmod tempor incididunt u--\u003Et labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud \u003C/style\u003E exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\u0027","TestCases":[{"Name":"Loop with moving IndexOf","Code":"function escapeMatchingClosingTag(rawText, parentTag) {\r\n const text = [...rawText];\r\n const lowercasedRawText = rawText.toLowerCase();\r\n const pattern = \u0027\u003C/\u0027 \u002B parentTag.toLowerCase() \u002B \u0027\u003E\u0027;\r\n let start = 0;\r\n\r\n while(start \u003C lowercasedRawText.length) {\r\n const indexOfClosingTag = lowercasedRawText.indexOf(pattern, start);\r\n if (indexOfClosingTag === -1) {\r\n break;\r\n }\r\n\r\n const indexOfCommentStart = lowercasedRawText.indexOf(\u0027\u003C!--\u0027, start);\r\n if (indexOfCommentStart === -1) {\r\n // No Comment found\r\n text[indexOfClosingTag] = \u0027\u0026lt;\u0027;\r\n start =indexOfClosingTag \u002B pattern.length-1;\r\n } else if (indexOfCommentStart \u003C indexOfClosingTag) {\r\n const indexOfCommentEnd = lowercasedRawText.indexOf(\u0027--\u003E\u0027, indexOfCommentStart\u002B4);\r\n if (indexOfClosingTag \u003E indexOfCommentEnd) {\r\n // Closing tag is not comment.\r\n text[indexOfClosingTag] = \u0027\u0026lt;\u0027;\r\n start =(indexOfClosingTag \u002B pattern.length-1);\r\n } else {\r\n start =(indexOfCommentEnd \u002B 2);\r\n }\r\n }\r\n }\r\n\r\n return text.join(\u0027\u0027)\r\n }\r\n\r\nescapeMatchingClosingTag(rawText, \u0027style\u0027);","IsDeferred":false},{"Name":"While loop with substring","Code":"function escapeMatchingClosingTag(rawText, parentTag) {\r\n let result = \u0027\u0027;\r\n let i = 0;\r\n let isInCommentBlock = false;\r\n const lowercasedRawText = rawText.toLowerCase();\r\n const pattern = \u0027\u003C/\u0027 \u002B parentTag.toLowerCase() \u002B \u0027\u003E\u0027;\r\n while (i \u003C rawText.length) {\r\n let currentChar = rawText[i];\r\n if (isInCommentBlock) {\r\n if (rawText.substr(i, 3) === \u0027--\u003E\u0027) {\r\n // We came across a closing comment tag while being in\r\n // a comment block. Set the flag and proceed to the next char.\r\n isInCommentBlock = false;\r\n }\r\n } else {\r\n if (rawText.substr(i, 4) === \u0027\u003C!--\u0027) {\r\n // We came across an open comment tag,\r\n // set the flag and proceed to the next char.\r\n isInCommentBlock = true;\r\n } else {\r\n // We are not in comment block, check if we have\r\n // a lookup pattern in front of us. Compare against\r\n // a lowercased content to avoid case sensitivity.\r\n if (lowercasedRawText.substr(i, pattern.length) === pattern) {\r\n currentChar = \u0027\u0026lt;\u0027; // replace \u0027\u003C\u0027 with \u0027\u0026lt;\u0027\r\n }\r\n }\r\n }\r\n result \u002B= currentChar;\r\n i\u002B\u002B;\r\n }\r\n return result;\r\n}\r\nescapeMatchingClosingTag(rawText, \u0027style\u0027);","IsDeferred":false}]}