123456789101112 |
- function isPalindrome(input) {
- const regex = /[\W_]/g;
- input = input.toLowerCase().replace(regex, '');
- let len = input.length;
- for (let i = 0; i < len/2; i++) {
- if (input[i] !== input[len - 1 - i]) {
- return false;
- }
- }
- return true;
- }
- console.log(isPalindrome("A man, a plan, a canal. Panama"));
|