-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpalindrome.js
More file actions
23 lines (20 loc) · 840 Bytes
/
Copy pathpalindrome.js
File metadata and controls
23 lines (20 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
Return true if the given string is a palindrome. Otherwise, return false.
palindrome("eye"); // true
palindrome("_eye") // true.
palindrome("race car") // true.
palindrome("not a palindrome") // false.
palindrome("A man, a plan, a canal. Panama") // true.
palindrome("never odd or even") // true.
palindrome("nope") // false.
palindrome("almostomla") // false.
palindrome("My age is 0, 0 si ega ym.") // true.
*/
function palindrome(str) {
//comparing original string with reversed string
if (str.replace(/[\W_]/g, '').toLowerCase() ===
str.replace(/[\W_]/g, '').toLowerCase().split('').reverse().join("")) {
return true;
}
return false;
}