{"ScriptPreparationCode":null,"TestCases":[{"Name":"for loop","Code":"function randomNumber(min, max) {\r\n const range = max - min;\r\n const randomNumber = Math.random() * range;\r\n return randomNumber \u002B min;\r\n}\r\n\r\nfunction word(length) {\r\n let result = \u0022\u0022;\r\n const characters = \u0022ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\u0022;\r\n const charactersLength = characters.length;\r\n let counter = 0;\r\n while (counter \u003C length) {\r\n result \u002B= characters.charAt(Math.floor(Math.random() * charactersLength));\r\n counter \u002B= 1;\r\n }\r\n return result;\r\n}\r\n\r\nconst sentences = [];\r\nlet targetWords = 10_000;\r\n\r\nwhile (targetWords \u003E 0) {\r\n const numWords = randomNumber(1, 20);\r\n const words = [];\r\n for (let i = 0; i \u003C numWords; i\u002B\u002B) {\r\n words.push(word(randomNumber(3, 7)));\r\n }\r\n sentences.push(words.join(Math.random() \u003E 0.5 ? \u0022\\n\u0022 : \u0022 \u0022));\r\n targetWords -= numWords\r\n}\r\n\r\nfunction isWhitespace(c) {\r\n return c === \u0022 \u0022 || c === \u0022\\n\u0022;\r\n}\r\n\r\nfunction countWords(s) {\r\n let count = 0;\r\n let onWhitespace = true;\r\n for (const c of s) {\r\n if (onWhitespace) {\r\n if (!isWhitespace(c)) {\r\n onWhitespace = false;\r\n count \u002B= 1;\r\n }\r\n } else if (isWhitespace(c)) {\r\n onWhitespace = true;\r\n }\r\n }\r\n return count;\r\n}\r\n\r\nsentences.map(countWords)","IsDeferred":false},{"Name":"regex","Code":"function randomNumber(min, max) {\r\n const range = max - min;\r\n const randomNumber = Math.random() * range;\r\n return randomNumber \u002B min;\r\n}\r\n\r\nfunction word(length) {\r\n let result = \u0022\u0022;\r\n const characters = \u0022ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\u0022;\r\n const charactersLength = characters.length;\r\n let counter = 0;\r\n while (counter \u003C length) {\r\n result \u002B= characters.charAt(Math.floor(Math.random() * charactersLength));\r\n counter \u002B= 1;\r\n }\r\n return result;\r\n}\r\n\r\nconst sentences = [];\r\nlet targetWords = 10_000;\r\n\r\nwhile (targetWords \u003E 0) {\r\n const numWords = randomNumber(1, 20);\r\n const words = [];\r\n for (let i = 0; i \u003C numWords; i\u002B\u002B) {\r\n words.push(word(randomNumber(3, 7)));\r\n }\r\n sentences.push(words.join(Math.random() \u003E 0.5 ? \u0022\\n\u0022 : \u0022 \u0022));\r\n targetWords -= numWords\r\n}\r\n\r\nconst reg = new RegExp(/\\S\u002B/g)\r\n\r\nfunction countWords(string) {\r\n const words = string.match(reg);\r\n return words ? words.length : 0;\r\n}\r\n\r\nsentences.map(countWords)","IsDeferred":false}]}