From 8dfcd1eb07d1ae8c7f37a6ced4233befb7c64b3e Mon Sep 17 00:00:00 2001 From: Isah Jacob Date: Mon, 31 Oct 2022 22:41:59 +0100 Subject: [PATCH] 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; --- 09_palindromes/palindromes.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/09_palindromes/palindromes.js b/09_palindromes/palindromes.js index 8d21018..50ca9c7 100644 --- a/09_palindromes/palindromes.js +++ b/09_palindromes/palindromes.js @@ -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;