// 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");
Comments
Leave a comment