regex - delete a space after a period javascript -
i trying write funciton in javascript delete spaces , punctuation in sentence, , check if it's palindrome. i've gotten of work, won't delete space after period in canal. how can this?
function palindrome(str) { str = str.tolowercase(); str = str.replace(/\s+/g, ''); str = str.replace(/,/g , ""); str = str.split('.').join(' '); document.write(str); if(str.split("").reverse().join("") === str) { return true; } else { return false; } } palindrome("a man, plan, canal. panama");
i use 1 replace spaces, commas, , periods
function palindrome(str) { str = str.tolowercase(); str = str.replace(/[\s,\.]+/g, ''); document.write(str); if(str.split("").reverse().join("") === str) { return true; } else { return false; } } console.log(palindrome("a man, plan, canal. panama"));
Comments
Post a Comment