You are viewing a single comment's thread. Return to all comments →
This is my solution in JS. But it does not pass every case, I tried to find what's wrong about it, but no idea. Any thoughts?
function palindromeIndex(s) { let charArray = s.split('') let copyArray = charArray.map(x => x) let secondCopyArray = copyArray.map(x => x) let result = -1 if(charArray.join('') === copyArray.reverse().join('')){ return result } copyArray.reverse() for(let i = 0; i < charArray.length; i++){ copyArray.splice(i, 1) secondCopyArray.splice(i, 1) secondCopyArray.reverse() if(secondCopyArray.join(',') === copyArray.join(',')){ result = i break } copyArray = charArray.map(x => x) secondCopyArray = charArray.map(x => x) } return result }
Seems like cookies are disabled on this browser, please enable them to open this website
Palindrome Index
You are viewing a single comment's thread. Return to all comments →
This is my solution in JS. But it does not pass every case, I tried to find what's wrong about it, but no idea. Any thoughts?