Tell us what’s happening:
My code returns a boolean, however FCC is suggesting that it’s not. I don’t quite understand why this is happening. any help would be greatly appreciated.
My code is basically breaking the letters down to their charCodes and comparing a string of numbers instead of letters.
If you would like to see the results of ‘base’ and ‘reversed’ just replace the returned statement with the following: return [base, reversed] so you can see the results in an array.
Your code so far
function palindrome(str) {
// Good luck!
let re = /[a-z]/gi;
let base = str.match(re)
.map(e => [e.toLowerCase().charCodeAt()])
.flat()
.join('');
let reversed = str.split(' ')
.sort((a,b) => b - a)
.map(e => e.split('').sort((a,b) => b - a))
.map(e => e.join('').toLowerCase())
.join('')
.match(re)
.map(e => e.charCodeAt())
.join('');
return base == reversed ;
}
palindrome("eye");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
.
Challenge: Palindrome Checker
Link to the challenge: