used .tolowercase metheod to convert every string to lower changes

I used also .replace with regular expression that will match anything between A-Z, and a-z and replace afterwards
processed the string using .split, .reverse, and .join method
and the function return true if processedString is equal to reversedString;
This commit is contained in:
Isah Jacob 2022-10-31 22:41:59 +01:00
parent 879d67a4b2
commit 8dfcd1eb07
1 changed files with 12 additions and 4 deletions

View File

@ -1,6 +1,14 @@
const palindromes = function () {
const palindromes = function(string) {
let processedString = string.toLowerCase().replace(/[^A-Za-z]/g, "");
let reversedString = (
processedString
.split("") // ["v","u","d","a","n","g"]
.reverse() // ["g","n","a","d","u","v"]
.join("") // "gnaduv"
);
return processedString == reversedString; // false because "vudang" =! "gnaduv"
};
palindromes('racecar')
// Do not edit below this line
module.exports = palindromes;