odin-default-js-exercises/09_palindromes/palindromes.js

26 lines
469 B
JavaScript

const palindromes = function (string) {
let result = string
.toUpperCase()
.replace(/[_\W]+/g, "")
.split(" ")
.join("")
.split("")
.join("");
let reverseResult = string
.toUpperCase()
.replace(/[_\W]+/g, "")
.split(" ")
.join("")
.split("")
.reverse()
.join("");
if (result === reverseResult) {
return true;
} else {
return false;
}
};
// Do not edit below this line
module.exports = palindromes;