1
- /* JavaScript Algorithms and Data Structures Projects: Palindrome Checker
1
+ JavaScript Algorithms and Data Structures Projects: Palindrome Checker
2
2
Return true if the given string is a palindrome. Otherwise, return false.
3
3
4
4
A palindrome is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.
@@ -8,11 +8,10 @@ You'll need to remove all non-alphanumeric characters (punctuation, spaces and s
8
8
9
9
We'll pass strings with varying formats, such as "racecar", "RaceCar", and "race CAR" among others.
10
10
11
- We'll also pass strings with special symbols, such as "2A3*3a2", "2A3 3a2", and "2_A3*3#A2"./**/
12
-
11
+ We'll also pass strings with special symbols, such as "2A3* 3a2", "2A3 3a2", and "2_A3* 3#A2".
13
12
13
+ ``` js
14
14
function palindrome (str ) {
15
- // Good luck!
16
15
str = str .replace (/ [\W _] / g , ' ' ).toLowerCase ();
17
16
18
17
let rev = str .split (' ' ).reverse ().join (' ' );
@@ -25,10 +24,10 @@ function palindrome(str) {
25
24
26
25
27
26
palindrome (" eye" );
27
+ ` ` ` js
28
28
29
-
30
- /*[ and ] are the start and end of a character set.
31
- \W means "non-word", as opposed to \w which will match a word.
32
- _ is the "_" character.
33
- / mark the beginning and end of a regular expression.
34
- g means it's a global search.*/
29
+ * [ and ] are the start and end of a character set.
30
+ * \W means "non-word", as opposed to \w which will match a word.
31
+ * _ is the "_" character.
32
+ * / mark the beginning and end of a regular expression.
33
+ * g means it's a global search.
0 commit comments