function palindrome(str) {
let rStr = str
.toLowerCase()
.split(/[_\W\s]+/g)
.map(word => word.split("").reverse().join(""))
.reverse()
.join("");
if(rStr === str.toLowerCase().split(/[_\W\s]+/g).join("")){
return true;
}
return false;
}
palindrome("A man, a plan, a canal. Panama");
Did it pass the tests?
If it passes, it’s acceptable.
You could tidy it up a bit though. You split, reverse, and join inside of a map for a split, reverse, and join. This means that you’re repeating yourself.
Repeating yourself is a bit of a red flag that you’re doing more work than you need to.
Yeah that’s what I was wondering. How do I make it more dry?
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.