Skip to content

Commit dad84dc

Browse files
committed
completed the palindrome checker
1 parent 7aa9dbd commit dad84dc

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Palindrome_Checker/script.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function palindrome(str) {
2+
// use regex to replace non-string to nothing also changing all letters to lowercase
3+
str = str.replace(/\W|_/g, "").toLowerCase();
4+
// reverse each words by spliting them and joining them again
5+
let reverse = str.split("").reverse().join("");
6+
// compare if the reversed string is the same as the prior string. return true if that is true and false if it is not
7+
if (reverse === str) return true
8+
return false
9+
}
10+
11+
palindrome("eye");

0 commit comments

Comments
 (0)