Check for Palindromes - can't filter the digits

Check for Palindromes - can't filter the digits
0.0 0

#1

Tell us what’s happening:
Hello,

can’t find out why ‘filtered’ var can’t filter digits from ‘toReduce’ array? I’ve tried to filter letters from the ‘toReduce’ array like “o” and it works out. On the other hand I just can’t filter digits. Anyone can help here?

Your code so far

function palindrome(str) {
  // Good luck!
  var lowLetter = str.toLowerCase();
  var toReduce = lowLetter.split("");
  var filtered = toReduce.filter(function(x) {
    return x != /\d/gi;
  });
  
  return filtered;
}



palindrome("8not a palindrome8");

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/62.0.3202.94 Safari/537.36.

Link to the challenge:


#2

To remove characters from a string using regex, use the .replace() function on the string.

var filtered = toReduce.replace(/\d/gi, '');

#3

If you wanted to use the filter method like you have though, you can tweak your existing code a little, using the .test() method for regex values:


#4

Thank you. Never heard about this ‘test’ method. I’m pretty sure it’s something that wasn’t explained in previous lessons. Anyway, I’ll test this!


#5

There’s loads missing from the lessons - they just get you started really.

Reading the documentation for all the different languages / frameworks / technologies you encounter is key - you can dig up all sorts of treasures in those.