js1 |
for (var i = 0; i < arr.length; i++) { if (answers[i] !== PatternChaser(arr[i])) { console.log('Sam P failed test ' + i); throw 'failed test ' + i; } }
function PatternChaser(str) { var i = 0; var strLength = str.length; var ptrMaxLength = Math.floor(strLength / 2);
while (ptrMaxLength > 1) { testLength = 1 + strLength - (ptrMaxLength * 2);
for (; i < testLength; i += 1) { if (str.indexOf(str.substr(i, ptrMaxLength), i + ptrMaxLength) > -1) { return "yes " + str.substr(i, ptrMaxLength); } } ptrMaxLength -= 1; i = 0; } return "no null"; }
|
pending… |
js2 |
for (var i = 0; i < arr.length; i++) { if (answers[i] !== PatternChaser(arr[i])) { console.log('Sam P failed test ' + i); throw 'failed test ' + i; } }
function PatternChaser(str) { var strLength = str.length; var ptrMaxLength = Math.floor(strLength / 2); var maxPosLength = (strLength + 1) - (ptrMaxLength + ptrMaxLength);
while (ptrMaxLength > 1) { var i, testStr, passIndex = null; for (i = 0; i < maxPosLength; i += 1) { testStr = str.substr(i, ptrMaxLength); passIndex = i + ptrMaxLength; if (str.lastIndexOf(testStr) >= passIndex) { return "yes " + testStr; } } ptrMaxLength -= 1; maxPosLength += 2; } return "no null"; }
|
pending… |
js3 |
for (var i = 0; i < arr.length; i++) { if (answers[i] !== PatternChaser(arr[i])) { console.log('Sam P failed test ' + i); throw 'failed test ' + i; } }
function PatternChaser(str) { var strLength = str.length; var ptrMaxLength = Math.floor(strLength / 2); var maxPosLength = (strLength + 1) - (ptrMaxLength + ptrMaxLength);
while (ptrMaxLength > 1) { var i, testStr, passIndex = null; for (i = 0; i < maxPosLength; i += 1) { testStr = str.substr(i, ptrMaxLength); passIndex = i + ptrMaxLength - 1; if (str.lastIndexOf(testStr) > passIndex) { return "yes " + testStr; } } ptrMaxLength -= 1; maxPosLength += 2; } return "no null"; }
|
pending… |
js4 |
for (var i = 0; i < arr.length; i++) { if (answers[i] !== PatternChaser(arr[i])) { console.log('Sam P failed test ' + i); throw 'failed test ' + i; } }
function PatternChaser(str) { var strLength = str.length; var ptrMaxLength = Math.floor(strLength / 2); var maxPosLength = (strLength + 1) - (ptrMaxLength + ptrMaxLength);
while (ptrMaxLength > 1) { var i, testStr = null; var passIndex = ptrMaxLength - 1; for (i = 0; i < maxPosLength; i += 1) { testStr = str.substr(i, ptrMaxLength); passIndex += i; if (str.lastIndexOf(testStr) > passIndex) { return "yes " + testStr; } } ptrMaxLength -= 1; maxPosLength += 2; } return "no null"; }
|
pending… |
js5 |
for (var i = 0; i < arr.length; i++) { if (answers[i] !== PatternChaser(arr[i])) { console.log('Sam P failed test ' + i); throw 'failed test ' + i; } }
function PatternChaser(str) { var strLength = str.length; var ptrMaxLength = Math.floor(strLength / 2); var maxPosLength = (strLength + 1) - (ptrMaxLength + ptrMaxLength);
while (ptrMaxLength > 1) { var i = 0; var testStr = null; var passIndex = ptrMaxLength; for (i = 0; i < maxPosLength; i += 1) { testStr = str.substr(i, ptrMaxLength); passIndex += i; if (str.lastIndexOf(testStr) >= passIndex) { return "yes " + testStr; } } ptrMaxLength -= 1; maxPosLength += 2; } return "no null"; }
|
pending… |
js6 |
for (var i = 0; i < arr.length; i++) { if (answers[i] !== PatternChaser(arr[i])) { console.log('js6 failed test ' + i); throw 'failed test ' + i; } }
function PatternChaser(str) { var temp; var temp1; var size = str.length; var half; var final = "*"; var final_len;
for (var i = 0; i < size; i++) { half = Math.floor((size - i) / 2); final_len = final.length;
if (final_len < half) { for (; half > 0; half--) { // temp.length = half if (half > 1 && final_len < half) { temp = str.substring(i, i + half); temp1 = str.substring(i + half, size); if (temp1.indexOf(temp) !== -1) { if (half > final.length) return 'yes ' + temp; } } } } }
if (final.length > 1) return 'yes ' + final; else return 'no null'; }
|
pending… |
0 comments