Hi, everyone! First time, long time!
Took a lot more time than I’m willing to admit on this particular problem-
Thing is, I’ve noticed that a lot of people aren’t using arrays on their solution- using array methods, yes, but just on strings. When I first read this question, I immediately thought of splitting this into an array so as to pop and shift each match off.
This code passed but I’m wondering what you’d make of this approach.
Thank you for taking the time.
Your code so far
function palindrome(str) {
var result = true;
var stripped = str.replace(/[\W_]/g, '').toLowerCase();
var arr = stripped.split('');
for (var i = 0; i < arr.length; i++){
if (arr[i] === arr[arr.length-1-i]) {
arr.shift();
arr.pop();
} else {
result = false;
}
}
return result;
}
palindrome("1 eye for of 1 eye");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/check-for-palindromes