Palindrom v5
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) {
let tempStr = str.match(/[a-z0-9]+/ig).join('').toLowerCase()
console.log(tempStr)
let second = tempStr.split('').reverse().join('')
console.log(second)
return tempStr === 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 regex function with match method JavaScript build in method match()
We use (/[a-z0-9]+/ig) => we check from a - z and 0 - 9; i = ignores casing ; g = global; + = returns the repetitions
We chained Javascript build in method join() and toLowerCase()
We create another variable second that split the tempStr 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 tempStr is equal to second.