JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" id="LOWERLIMIT" value="0x20"> (Lower)<br>
<input type="text" id="UPPERLIMIT" value="0xffff"> (Upper)<br>
<input type="button" value="Test efficient" onclick="init_test(0)"> •
<input type="button" value="Test excluding space(0x20)" onclick="init_test(1)" title="This separates every character by a space, for a more accurate comparison (when a character's length == 2)"><br>
<input type="button" value="Test try-catch" onclick="init_test(2)"><br>
<textarea id="output"></textarea>
CSS
html,body{height:100%}
#output{width:90%;height:70%;}
JavaScript
// Global variables for debugging first test case
var input = '', output = '';
function init_test(func) {
// argument func = 0, 1 or 2
func = [run_test, run_testSpace, run_testSlow][func];
document.getElementById('output').value = navigator.userAgent + '\n\n' + func(
parseInt(document.getElementById('LOWERLIMIT').value),
parseInt(document.getElementById('UPPERLIMIT').value)
);
// parseInt without radix, so that 0xff -> 255
}
// Clean-up
window.onunload = function() {
localStorage.removeItem('chartest');
};
function run_test(lowerlimit, UPPERLIMIT) {
try {
if (!window.localStorage) {
// I recall that in one of the older Chrome versions,
// localStorage === null
return 'Localstorage is not supported';
}
if (isNaN(lowerlimit) || isNaN(UPPERLIMIT) || lowerlimit > UPPERLIMIT) {
return 'One of the limits is not a valid number!';
}
var i = lowerlimit - 1;
var character_range = [];
while (++i < UPPERLIMIT) character_range.push(i);
input = String.fromCharCode.apply(String, character_range);
localStorage.setItem('chartest', input);
output = localStorage.getItem('chartest');
if (input === output) {
return true;
}
// Uh oh, not equal!
var result = [];
for (i=0; i<UPPERLIMIT-lowerlimit; i++) {
if (input[i] !== output[i]) {
result.push(i+lowerlimit);
}
}
return result;
}catch(e){return 'Error:' + e;}
}
// This function is not added to the interface, because it's intended for console-use.
function run_testSpace(lowerlimit, UPPERLIMIT) {
try {
if (!window.localStorage) {
// I recall that in one of the older Chrome versions,
// localStorage === null
return 'Localstorage is not supported';
}
if (isNaN(lowerlimit) || isNaN(UPPERLIMIT) ||...