Editing Identifying Hexadecimal Strings This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) Each test must return true for all numbers that would be interpreted by major web browsers as a hexadecimal number, but in the string type. Remember that all acceptable hexadecimal numbers begin with "0x...", where the "x" may be uppercase. Furthermore, remember that a negative hexadecimal number would lead with a negative sign (i.e. "-0x..."). Important note: There MUST be an assumption that the string does contain a number! This means that simply searching for the letter "x" (uppercase or lowercase) is sufficient. Second important note: Since the string is unlikely to be a hexadecimal string, I have tested for "false" a greater number of times than true. Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) var hexString = "0x12345"; var nonHexString = "12345"; var longHexString = "-0X123456789123456789"; var longNonHexString = "123456789123456789"; function charAt(str) { if (str.charAt(1).toLowerCase() === "x" || str.charAt(2).toLowerCase() === "x") { return true; }; }; function charAtTwo(str) { if (str.charAt(1) === "x" || str.charAt(2) === "x" || str.charAt(1) === "X" || str.charAt(2) === "X") { return true; }; }; function regExp(str) { if (/x/i.test(str)) { return true; }; }; function indexOf(str) { if (str.toLowerCase().indexOf("x") > -1) { return true; }; }; function indexOfTwo(str) { if (str.indexOf("x") > -1 || str.indexOf("X") > -1) { return true; }; }; Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code charAt(hexString); charAt(longHexString); charAt(nonHexString); charAt(longNonHexString); charAt(nonHexString); charAt(longNonHexString); charAt(nonHexString); charAt(longNonHexString); Test 2 Title Async (check if this is an asynchronous test) Code charAtTwo(hexString); charAtTwo(longHexString); charAtTwo(nonHexString); charAtTwo(longNonHexString); charAtTwo(nonHexString); charAtTwo(longNonHexString); charAtTwo(nonHexString); charAtTwo(longNonHexString); Test 3 Title Async (check if this is an asynchronous test) Code indexOf(hexString); indexOf(longHexString); indexOf(nonHexString); indexOf(longNonHexString); indexOf(nonHexString); indexOf(longNonHexString); indexOf(nonHexString); indexOf(longNonHexString); Test 4 Title Async (check if this is an asynchronous test) Code indexOfTwo(hexString); indexOfTwo(longHexString); indexOfTwo(nonHexString); indexOfTwo(longNonHexString); indexOfTwo(nonHexString); indexOfTwo(longNonHexString); indexOfTwo(nonHexString); indexOfTwo(longNonHexString); Test 5 Title Async (check if this is an asynchronous test) Code regExp(hexString); regExp(longHexString); regExp(nonHexString); regExp(longNonHexString); regExp(nonHexString); regExp(longNonHexString); regExp(nonHexString); regExp(longNonHexString);