2022-09-06 12:18:39 +00:00
|
|
|
const palindromes = function (val) {
|
|
|
|
/*
|
|
|
|
let separatedBy = [" ", "!", ".", ","];
|
|
|
|
let separated;
|
|
|
|
let reversed;
|
|
|
|
let joined = val;
|
|
|
|
let removed
|
2017-08-25 19:07:28 +00:00
|
|
|
|
2022-09-06 12:18:39 +00:00
|
|
|
for (i = 0; i < separatedBy.length; i++) {
|
|
|
|
let temp = joined.split(separatedBy[i]);
|
|
|
|
joined = temp.join("");
|
|
|
|
}
|
|
|
|
removed = joined.split("");
|
|
|
|
for (i = removed.length - 1; i >= 0; i--) {
|
|
|
|
reversed.push(separated[i]);
|
|
|
|
}
|
|
|
|
if (separated === reversed) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
let separatedBy = [" ", "!", ".", ","];
|
|
|
|
let separated = val.toLowerCase().split("");
|
|
|
|
let reversed = [];
|
|
|
|
|
|
|
|
for (i = 0; i < separatedBy.length; i++) {
|
|
|
|
separated = separated.filter(function (d) {
|
|
|
|
return d != separatedBy[i];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
for (i = separated.length - 1; i >= 0; i--) {
|
|
|
|
reversed.push(separated[i]);
|
|
|
|
}
|
|
|
|
if (separated.join("") === reversed.join("")) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2021-03-03 02:13:24 +00:00
|
|
|
};
|
2017-08-25 19:07:28 +00:00
|
|
|
|
2021-09-11 22:18:19 +00:00
|
|
|
// Do not edit below this line
|
2021-03-03 02:13:24 +00:00
|
|
|
module.exports = palindromes;
|