Finding palindromes and the longest word in a string I have two little projects that I've been working on.

One is to find all palindromes:

function palindrome(str) {
  var replaceStrChr = str.replace(/\W/g,'').replace(/ /g,'').replace(/_/g,'').toLowerCase();
  var arrayifyStr = replaceStrChr.split('').reverse();
  var stringifyStr = arrayifyStr.join('');

  if (replaceStrChr === stringifyStr){
    return true;
  } else {
    return false;
  }
}


And the other one is to find the longest word in a string:

function findLongestWord(str){
    var arrayify = str.split(' ');
    var longest = 0;

    for(var x = 0; x &lt; arrayify.length; x++){
        if (arrayify[x].length &gt; longest){
            longest = arrayify[x].length;
        }
    }
    return longest;
}


What I'm looking for is a better way to do these, shortcuts, better syntax, etc.
For the palindrome:


You can probably just use one replace operation, but with a more extensive regex. My regex is rusty but something like /[\W_\s]/g could do.
split, reverse and join could possibly be just one chain.

var reversedString = replaceStrChr.split('').reverse().join('');

Comparisons are essentially boolean values. You can simply do:

return replaceStrChr === stringifyStr;



For the longest word:


Use reduce and carry through the longest word.

var longestWord = str.split(' ').reduce(function(prev, next){
  return next.length &gt; prev.length ? next : prev;
});

str doesn't tell me what the string contains. Only when I saw split(' ') did I realize it was a space-separated string. Rename the variable to show its purpose.