-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalindrome.js
More file actions
25 lines (20 loc) · 739 Bytes
/
palindrome.js
File metadata and controls
25 lines (20 loc) · 739 Bytes
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
function isPalindrome(string) {
string = string.toLowerCase();
const arr = string.split('');
const validCharacteres = 'abcdefghijklmnopqrstuvxz'.split('');
const lettersArr = [];
arr.forEach(char => {
if (validCharacteres.indexOf(char) > -1) {
lettersArr.push(char);
}
});
if (lettersArr.join('') === lettersArr.reverse().join('')) {
return true;
}
return false;
}
console.log(isPalindrome('race car'));
// Receives a string and return true if the string is a Palindrome and return false if the string is not a Palindrome
// Palindrome is a string that spelled the same way both backward and foward
// example race car is a palindrome
// example Madam, I'm Adam