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 < arrayify.length; x++){
if (arrayify[x].length > longest){
longest = arrayify[x].length;
}
}
return longest;
}
What I'm looking for is a better way to do these, shortcuts, better syntax, etc.