From f874c80586e17cd005f91c48dd317ad933887cac Mon Sep 17 00:00:00 2001 From: shakurbol Date: Sun, 8 Oct 2023 22:08:14 +0300 Subject: [PATCH] first commit --- index.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/index.js b/index.js index 681f973..f0cb26d 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,39 @@ function isPalindrome(word) { // Write your algorithm here + +function isPalindrome(inputStr) { + + const cleanedStr = inputStr.replace(/[^a-zA-Z0-9]/g, '').toLowerCase(); + const reversedStr = cleanedStr.split('').reverse().join(''); + return cleanedStr === reversedStr; +} +console.log(isPalindrome("racecar")); +console.log(isPalindrome("A man, a plan, a canal, Panama")); +console.log(isPalindrome("hello")); + } /* Add your pseudocode here */ +function isPalindrome(inputStr) { + + let reversedStr = inputStr.split('').reverse().join(''); + + + if (reversedStr === inputStr) { + return true; + } else { + return false; + } +} + +// Example usage: +console.log(isPalindrome("racecar")); // Should return true +console.log(isPalindrome("hello")); // Should return false + + /* Add written explanation of your solution here */