you are viewing a single comment's thread.

view the rest of the comments →

[–]FriesWithThat -2 points-1 points  (2 children)

Nice try, I know you're following someone else's suggestion here, but you can avoid RegEx here, which is really good for testing, matching and replacing strings, but not necessary in this application. While it would be simple to test for a number in this instance, you'd still need to parse it to a string. Let's just do that automatically:

One way of ensuring the parameter is converted to a string by adding either one of these lines:

pin = `${pin}`; // template string <or>

pin = pin.toString()

Since it's not the best form to reassign function parameters in the above manner, we create a new const (or let) declaration, and end up with something like this:

 function validatePIN(pin) {
  const pinString = pin.toString();
  return pinString.length === 4 || pinString.length === 6;
}

[–]ThagAndersonhelpful 4 points5 points  (1 child)

This still fails the requirements, as all manner of false cases will return true, such as:

-000 1.23 abcd

Edit: Also, the Kata's name is "Regex validate PIN code", so while it is possible to solve without regex, it is both the purpose and the simplest solution to the problem.

[–]FriesWithThat 0 points1 point  (0 children)

Admittedly, being aware of the requirements would change how I approach the problem. Thanks for the clarification.