added answers

This commit is contained in:
Jared Ramon Elizan 2022-08-14 09:52:30 +08:00
parent 94be66c211
commit ea3e861799
1 changed files with 17 additions and 1 deletions

View File

@ -1,6 +1,22 @@
const palindromes = function () {
const palindromes = function (word) {
const punctuationsAndWordBreaks = /[!"@#$%^&*()_+-<>?/.,\s|`~]/g;
let pureString = word.toLowerCase();
pureString = pureString.replace(punctuationsAndWordBreaks, "");
let result = "";
for(let i = pureString.length - 1; i >= 0; i--){
result += pureString[i];
}
if( result === pureString ){
return true;
} else{
return false;
}
};
console.log(palindromes('Racecar!')); //should return true
console.log(palindromes('A car, a man, a maraca.')); //should return true
console.log(palindromes('Animal loots foliated detail of stool lamina.')); //should return true
// Do not edit below this line
module.exports = palindromes;