Palindrom v4
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 checkPalindrom(str) {
str = str.toLowerCase();
let first = str.split(' ').join('')
let second = first.split('').reverse().join('');
return first === second
}
console.log(checkPalindrom('hannah')) true
console.log(checkPalindrom('apple')) false
We create a function checkPalindrom(str) parameter str.
We turn the parameter into all characters in LowerCase with JavaScript build in method toLowerCase()
We create variable first and we split the parameter with space then we join using JavaScript build in methods split() and join()
We create another variable second that split the first variable without using space between reverse the order and join using the JavaScript build in methods split() reverse() join().
In the end we check with return if first is equal to second.