Answers for "palindrome hacker Rank challenge"

0

palindrome hacker Rank challenge

function isPalindrome(str){
  if(str === str.split('').reverse().join('')){
    return true
  }
  return false
}

function palindromeIndex(str) {
    if(str.length < 1) return -1
    
    let i = 0
    let j = str.length - 1
    
    while(i < j && str[i] == str[j]){
        i += 1
        j -= 1
    }
    
    if(isPalindrome(str.slice(0, i) + str.slice(i+1, str.length))){
      return i
    } 
    if(isPalindrome(str.slice(0, j) + str.slice(j+1, str.length))){
      return j
    } 
    return -1
}
Posted by: Guest on June-14-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language