{"ScriptPreparationCode":null,"TestCases":[{"Name":"Using For Loop","Code":"const generateTestText = (length) =\u003E {\r\n return \u0022A\u0022.repeat(length).replace(/A{75}/g, \u0022$\u0026\\n\u0022); // Insert newline every 75 characters\r\n};\r\n\r\nconst text = generateTestText(1000000);\r\n\r\nconst measurePerformance = (text) =\u003E {\r\n const charLimitPerLine = 75;\r\n const maxLines = 7;\r\n\r\n let totalLines = 0;\r\n let currentLineLength = 0;\r\n\r\n // Loop through the text and increase the total lines when a line break is found or it \r\n // has reached the char limit per line\r\n for (let i = 0; i \u003C text.length; i\u002B\u002B) {\r\n currentLineLength\u002B\u002B;\r\n\r\n if (text[i] === \u0027\\n\u0027 || text[i] === \u0027\\r\u0027 || currentLineLength \u003E= charLimitPerLine) {\r\n totalLines\u002B\u002B;\r\n currentLineLength = 0;\r\n }\r\n }\r\n\r\n // Account any remaining character in the last line\r\n if (currentLineLength \u003E 0) {\r\n totalLines\u002B\u002B;\r\n }\r\n\r\n return totalLines \u003E maxLines;\r\n};\r\n\r\nmeasurePerformance(text);","IsDeferred":false},{"Name":"Using Regex and Reduce","Code":"const generateTestText = (length) =\u003E {\r\n return \u0022A\u0022.repeat(length).replace(/A{75}/g, \u0022$\u0026\\n\u0022); // Insert newline every 75 characters\r\n};\r\n\r\nconst text = generateTestText(1000000);\r\n\r\nconst measurePerformance = (text) =\u003E {\r\n const charLimitPerLine = 75;\r\n const maxLines = 7;\r\n\r\n const lines = text.split(/\\r?\\n/);\r\n const totalLines = lines.reduce((count, line) =\u003E {\r\n return count \u002B Math.ceil(line.length / charLimitPerLine);\r\n }, 0);\r\n\r\n return totalLines \u003E maxLines || note.text.length \u003E 530;\r\n}\r\n\r\nmeasurePerformance(text);","IsDeferred":false}]}