-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalindromes
More file actions
19 lines (13 loc) · 877 Bytes
/
Copy pathpalindromes
File metadata and controls
19 lines (13 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function palindrome(str) {
var strRinsed = str.replace(/[^a-zA-Z0-9]/g, ''); //rinses our str of all non-alpha-nu characters, and stores it in a variable called strRinsed
var strLowered = strRinsed.toLowerCase(); //lowers the case of our strRinsed variable
var loweredStrArr = strLowered.split(''); //splits the letters of the string into an array, so that we can reverse it using .split
var arrRev = loweredStrArr.reverse(); //Reverses the letters in the array
var strRev = arrRev.join(''); //joins the reversed letters back into a string
if(strRev == strLowered){ //compares the reversed string to strLowered to see if theyre the same, if they are it returns true, otherwise false
console.log("true");
}
else
console.log("false");
}
palindrome("_Ey e");