Hi, everyone! Today I finished the fourth challenge of Basic Algorithms block - Check for Palindromes.
Although every test is positive, I feel like my solution is too bulky. I would like to figure our, how can I make it shorter but as functional as it is. Maybe there is some other algorithm that can deal with the problem in more efficient way.
Thank you for your advice in advance!
P.S. Thank you, freeCodeCamp for this initiative and the knowledge you give us.
function palindrome(str) {
var result,
newStr,
regExp = /[A-Za-z0-9]/,
arr = str.toLowerCase().split("");
arr = arr.filter(function(value){
return regExp.test(value);
});
newStr = arr.join("");
result = arr.reverse().join("").toLowerCase();
return newStr === result;
}