From d6ba50ae665eb0f56752f231d9f10f9174e3e95c Mon Sep 17 00:00:00 2001 From: omarshams97 <46492810+omarshams97@users.noreply.github.com> Date: Wed, 25 Aug 2021 11:49:39 -0300 Subject: [PATCH] Update palindrome.js Answer to Q1 --- tasks/1. Palindrome check/palindrome.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tasks/1. Palindrome check/palindrome.js b/tasks/1. Palindrome check/palindrome.js index fb585eb..084c283 100644 --- a/tasks/1. Palindrome check/palindrome.js +++ b/tasks/1. Palindrome check/palindrome.js @@ -1,3 +1,10 @@ export function isPalindrome(inputString) { - // TODO: write your code here -} \ No newline at end of file + //RegExp to remove unwanted characters from input string + var re = /[\W_]/g; + //turning all characters to lowercase and using RegExp to get rid of unwanted characters + var lowRegStr = inputString.toLowerCase().replace(re, ''); + //spliting the string into individual characters, reversing the character positions (first character becomes last, last becoms first ect) then recombining them into a string + var reverseStr = lowRegStr.split('').reverse().join(''); + //if the reverse string is equal to the intial it is a palindrome and return true, If not return false. + return reverseStr === lowRegStr; +}