You are viewing a single comment's thread. Return to all comments →
I was getting th same issue and I adjusted my code to suit the outputs. Here's my JS solution:
if(s.split(``).reverse().join(``) !== s){ let half = Math.floor(s.length * 0.5); for(let i = 0; i < half; i++){ let id = s.length - 1 - i; if(s.charAt(i) !== s.charAt(id)){ let sub = s.substring(i,id); if(sub === sub.split(``).reverse().join(``)){ return id; } sub = s.substring(i+1,id+1); if(sub === sub.split(``).reverse().join(``)){ return i; } else{ break; } } } } return -1;
Seems like cookies are disabled on this browser, please enable them to open this website
Computer Virus
You are viewing a single comment's thread. Return to all comments →
I was getting th same issue and I adjusted my code to suit the outputs. Here's my JS solution: