-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPalindromicStrings2.js
31 lines (24 loc) · 1.39 KB
/
PalindromicStrings2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<<<<<<< HEAD
// Write another function that returns true if the string passed as an argument is a palindrome, or false otherwise.
// This time, however, your function should be case-insensitive, and should ignore all non-alphanumeric characters
const isRealPalindrome = () => {
}
=======
/* eslint-disable indent */
/* eslint-disable max-len */
// Write another function that returns true if the string passed as an argument is a palindrome, or false otherwise.
// This time, however, your function should be case-insensitive, and should ignore all non-alphanumeric characters.
// If you wish, you may simplify things by calling the isPalindrome function you wrote in the previous exercise.
import { isPalindrome } from './PalindromicStrings1.js';
const isRealPalindrome = (input) => {
let searchPattern = new RegExp(/[^a-z0-9]/g);
let output = input.toLowerCase().replace(searchPattern, '');
return isPalindrome(output);
};
>>>>>>> 91925f5254d8ac1d857b946df65c0dda803527a4
console.log(isRealPalindrome('madam')); // true
console.log(isRealPalindrome('Madam')); // true (case does not matter)
console.log(isRealPalindrome("Madam, I'm Adam")); // true (only alphanumerics matter)
console.log(isRealPalindrome('356653')); // true
console.log(isRealPalindrome('356a653')); // true
console.log(isRealPalindrome('123ab321')); // false