DEV Community

[Comment from a deleted post]
Collapse
 
codewithnithin profile image
codeWithNithin

function checkPalindrome(inputString) {
let originalString = inputString;
let reversedString = originalString.split('').reverse().join('')
return originalString == reversedString;
}

let the originalString be a variable for argument input string.
let the reversedString be a variable that has reversed string
how the reverse proceducre is done?

  1. originalString.split('') , this will convert string to a array for ex: inputString = "aabaa"; then inputString.split('') will convert string to an array it will become ['a', 'a' , 'b' , 'a' , 'a']. then reverse() method just reverses the array and join() method just converts array to string.