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:
parent
879d67a4b2
commit
8dfcd1eb07
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue