Created
March 29, 2019 20:41
-
-
Save codesnakers/07f2899ccc394c945ef701ca5951b39b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Solution for: http://codesnakers.com/projects/4.png | |
*/ | |
function solution(S) { | |
// write your code in JavaScript (Node.js 8.9.4) | |
var len = S.length; | |
if(typeof S !== "string" || len===0 || len>1000000 || len===undefined){ | |
return 0; | |
} | |
var prefixS, suffixS; | |
for(var i=1; i<len; i++){ | |
prefixS = S.slice(i); | |
suffixS = S.slice(0,len-i); | |
/*console.log(prefixS, suffixS);*/ | |
if(prefixS === suffixS){ | |
return prefixS.length; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment