Palindrom-v6

Palindrom v6

Given a string, return a new string with the reversed order of characters.

Example:
console.log(checkPalindrom(‘hannah’)) true
console.log(checkPalindrom(‘apple’)) false

function palindrom(str){
  return str.split('').reverse().join('') === str ? true : false;
}

console.log(palindrom('hannah')) 
console.log(checkPalindrom('apple'))

We create a function palindrom(str) parameter str.
We return str.split(‘’) to turn the string into an array
We chain .reverse() to reverse the letters of the array
We chain .join(‘’) to join the letters into string
We chech with === if all above functions are reversing the string and check with original like this === str
Then we use ternery operation if it is true ? we return true : false

comments powered by Disqus