Skip to content

Instantly share code, notes, and snippets.

@codesnakers
Created March 29, 2019 20:41
Show Gist options
  • Save codesnakers/07f2899ccc394c945ef701ca5951b39b to your computer and use it in GitHub Desktop.
Save codesnakers/07f2899ccc394c945ef701ca5951b39b to your computer and use it in GitHub Desktop.
/**
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