Im stuck at understanding this exaple

Tell us what’s happening:
I followed with the palindrome examples on youtube and a couple other /examples why is it soo hard to follow with this one anyone got an easier explanation?
thanks in advance…freecodecamp is Amazing!!

Your code so far

function sum(arr, n) {
// Only change code below this line

// Only change code above this line

Your browser information:

User Agent is: Mozilla/5.0 (Linux; U; Android 9; en-us; TECNO KC8 Build/PPR1.180610.011) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.111 Mobile Safari/537.36 PHX/5.4.

Challenge: Replace Loops using Recursion

Link to the challenge:

Hey there!

This is how I solved the palindrome example:

function palindrome(str) {
  let pureStr = str.replace(/[\W_]/g, "").toLowerCase();
  return pureStr === pureStr


I have used regular expression to determine the input (which is a string in our case)
I have removed the characters that i don’t need and replaced it with blank.
To explain this = \W matches all except letters and numbers and underscore(_)
hence i have also added underscore as we dont need that aswell.
g at the end is to return multiple matches
and then we replace it with nothing,(we remove it)

Then I converted the remaining letters to lowercase

on the return statement we are trying to return boolean(true or false) by comparing the pureStr(the result of the above regex) with the reversed string of the same as we split the string into single characters and then reverse all from bottom to top and then join the reversed characters to form a string.

So if it is a palindrome (eye === eye) it returns true otherwise if it is not a palindrome, it would like this (axe === exa), which is false.

Hope this helps!! Cheers!

1 Like

Thats some good stuff right there but I was talki about the replacing the for loop with recursion … I was not exactly understanding it… but still thanks…

1 Like

your welcome!

I must try that too. sounds challenging!

Thanks :wink:

1 Like