Editing scramble 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) 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 arr = [ ['lehlowww', 'hello'], ['dlrwxdonexfe', 'oneworld'], ['oenhodwrol', 'oneworld'], ['rkqodlw', 'world'], ['olaelh', 'hello'], ['helio', 'hell'], ['abcewnorde', 'wonder'], ['wioskrngatwo', 'workingtwo'], ['locaacedo', 'locatedhere'], ['edfbenowaginning', 'beginningnow'], ['CAPS TEST', 'caps test'], ['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent et mauris magna, ac dapibus ipsum. Sed viverra feugiat vehicula. Pellentesque vel lacinia ipsum. Vestibulum vel diam vel velit mollis adipiscing. Suspendisse potenti. Duis elementum erat vitae neque blandit porttitor. Pellentesque pellentesque vulputate posuere. Pellentesque eget justo elit. Praesent elementum odio sit amet lectus dignissim tincidunt. In quam massa, varius nec convallis quis, luctus sed erat. Cras ut massa metus. Integer lacinia iaculis pretium.', 'luctus sed erat'] ]; var answers = [true, false, true, true, true, false, true, true, false, true, false, 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 for (var i = 0; i < arr.length; i++) { if (answers[i] !== StringScramble(arr[i][0], arr[i][1])) { console.log('Sam P failed test ' + i); throw 'failed test ' + i; } } function StringScramble(str1, str2) { if (str2.length > str1.length) return false; str1 = str1.split(""); str2 = str2.split(""); for (var i = 0; i < str2.length; i++) { if ((x = str1.indexOf(str2[i])) > -1) str1[x] = -1; else return false; } return true; } Test 2 Title Async (check if this is an asynchronous test) Code for (var i = 0; i < arr.length; i++) { if (answers[i] !== StringScramble(arr[i][0], arr[i][1])) { console.log('Sam P failed test ' + i); throw 'failed test ' + i; } } function StringScramble(str1, str2) { if (str2.length > str1.length) return false; str1 = str1.split(""); str2 = str2.split(""); for (var i = 0; i < str2.length; i += 1) { if ((x = str1.indexOf(str2[i])) > -1) str1[x] = -1; else return false; } return true; } Test 3 Title Async (check if this is an asynchronous test) Code for (var i = 0; i < arr.length; i++) { if (answers[i] !== StringScramble(arr[i][0], arr[i][1])) { console.log('Sam P failed test ' + i); throw 'failed test ' + i; } } function StringScramble(str1, str2) { if (str2.length > str1.length) return false; str1 = str1.split(""); for ( i = 0; i < str2.length; i++) { if ((x = str1.indexOf(str2[i])) > -1) str1[x] = -1; else return false; } return true; } Test 4 Title Async (check if this is an asynchronous test) Code for (var i = 0; i < arr.length; i++) { if (answers[i] !== StringScramble(arr[i][0], arr[i][1])) { console.log('Sam P failed test ' + i); throw 'failed test ' + i; } } function StringScramble(str1, str2) { if (str2.length > str1.length) return false; str2 = str2.split(""); for (var i = 0; i < str1.length; i++) { if ((x = str2.indexOf(str1[i])) < 0) return false; } return true; }