Answer to Question #114155 in HTML/JavaScript Web Application for Andre

Question #114155
Write function to check if word is palindrome. For example "radar" is palindrome, "hello" is not.
1
Expert's answer
2020-05-06T14:01:28-0400
// standart es6
const palindrome = (str) => {
  const reg = /[\W_]/g;
  let lowRegStr = str.toLowerCase().replace(reg, '');
  let reverseStr = lowRegStr.split('').reverse().join('');
  return reverseStr === lowRegStr;
}

palindrome("A man, a plan, a canal. Panama");

// common js
function palindrome(str) {
  var reg = /[\W_]/g;
  var lowRegStr = str.toLowerCase().replace(reg, '');
  var reverseStr = lowRegStr.split('').reverse().join('');
  return reverseStr === lowRegStr;
}

palindrome("A man, a plan, a canal. Panama");

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS