PALINDROME Intermediate Solution :::

PALINDROME Intermediate Solution :::
0

#1

Intermediate Code Solution:

function palindrome(str) {
str = str.toLowerCase().replace(/[\W_]/g, ‘’);
for(var i = 0, len = str.length - 1; i < len/2; i++) {
if(str[i] !== str[len-i]) {
return false;
}
}
return true;
}

WHY WE NEED TO DIVIDE LENGTH BY 2 ???


#2

this inside the for loop tells you to end looping at len/2, because in the if loop you’re comparing the beginning and end of the string and you will finish checking when you’re at the middle.
palindrome means a word or phrase has the same letters forward and backwards.