{"ScriptPreparationCode":"Array.prototype.flat = Array.prototype.flat || function flat(depth) {\r\n // This is the fastest method: https://www.measurethat.net/Benchmarks/Show/7815/0/array-concat-vs-spread-operator-vs-push-for-array-flat\r\n if (depth === undefined) { depth = 100; } else if (depth \u003C= 0) { return this; }\r\n var result = [];\r\n for (var len = this.length, i = 0, val; i \u003C len; \u002B\u002Bi) {\r\n if (Array.isArray((val = this[i]))) {\r\n val = val.flat(depth - 1);\r\n for (var jen = val.length, j = 0; j \u003C jen; \u002B\u002Bj) { result.push(val[j]); }\r\n } else {\r\n result.push(val);\r\n }\r\n }\r\n return result;\r\n} \r\n// Generates 400 sample strings at time of writing, some with no whitespace, some that are all whitespace, and some with a little of both\r\nvar sampleStrings = Array.from(document.body.childNodes)\r\n .map(x=\u003E x.textContent.split(\u0027\\n\u0027))\r\n .flat()\r\n .map(x=\u003E x.length\u003E10 \u0026\u0026 (x.length % 2 \u003E 0) ? x.trim() : x);\r\n\r\nvar whitespaceRgx = /^\\s*$/;\r\nvar isWhitespaceRgx = (str) =\u003E whitespaceRgx.test(str);\r\nvar isWhitespaceTrim = (str) =\u003E str.trim().length === 0;\r\n\r\nvar whitespaceRgxEarlyExit = /^\\s\u002B$/;\r\nvar isWhitespaceRgxWEarlyExit = (str) =\u003E str.length === 0 || whitespaceRgxEarlyExit.test(str);\r\nvar isWhitespaceTrimWEarlyExit = (str) =\u003E str.length === 0 || str.trim().length === 0;\r\n\r\nvar methods = [\r\n isWhitespaceRgx,\r\n isWhitespaceTrim,\r\n isWhitespaceRgxWEarlyExit,\r\n isWhitespaceTrimWEarlyExit\r\n];","TestCases":[{"Name":"isWhitespaceRgx","Code":"return sampleStrings.map(isWhitespaceRgx);","IsDeferred":false},{"Name":"isWhitespaceTrim","Code":"return sampleStrings.map(isWhitespaceTrim);","IsDeferred":false},{"Name":"isWhitespaceRgxWEarlyExit","Code":"return sampleStrings.map(isWhitespaceRgxWEarlyExit);","IsDeferred":false},{"Name":"isWhitespaceTrimWEarlyExit","Code":"return sampleStrings.map(isWhitespaceTrimWEarlyExit);","IsDeferred":false},{"Name":"Verify Correctness","Code":"let results = new Array(methods.length);\r\n\r\nfor(let samples=sampleStrings, len=samples.length, i=0; i\u003Clen; \u002B\u002Bi){\r\n for (let samp = samples[i], jen = methods.lenth, j=0; j\u003Cjen; \u002B\u002Bj) {\r\n results[j] = methods[j](samp);\r\n if (j \u003E 0 \u0026\u0026 results[j] !== results[j-1]) {\r\n \tthrow new Error(\u0060${methods[j].name}:${results[j]} does not match ${methods[j-1].name}:${results[j-1]} for: \\n${samp}\u0060); \r\n }\r\n }\r\n}","IsDeferred":false},{"Name":"2:isWhitespaceTrimWEarlyExit","Code":"// Run in reverse order from first 4 test\r\nreturn sampleStrings.map(isWhitespaceTrimWEarlyExit);","IsDeferred":false},{"Name":"2:isWhitespaceRgxWEarlyExit","Code":"// Run in reverse order from first 4 test\r\nreturn sampleStrings.map(isWhitespaceRgxWEarlyExit); ","IsDeferred":false},{"Name":"2:isWhitespaceTrim","Code":"// Run in reverse order from first 4 test\r\nreturn sampleStrings.map(isWhitespaceTrim);","IsDeferred":false},{"Name":"2:isWhitespaceRgx","Code":"// Run in reverse order from first 4 test\r\nreturn sampleStrings.map(isWhitespaceRgx);","IsDeferred":false}]}