12.17 Study Log

1.5h And another 12h day at work. Oof. I was happy to get another kata figured out in an evening, and even more so to get an answer close to the highest rated one. The kata tonight is about applying regex filters to a string as a way of validating a password. Not to see if it is the right password, but to make sure that it follows the password requirement checkboxes. I initially wasn’t sure how to combine everything into one regex, but I think it’s actually kind of nice to not have to do that. It makes it so much more readable, and easier to comment on as well.

// https://www.codewars.com/kata/52e1476c8147a7547a000811/train/javascript

// You need to write regex that will validate a password 
// to make sure it meets the following criteria:

// At least six characters long
// contains a lowercase letter
// contains an uppercase letter
// contains a number
// Valid passwords will only be alphanumeric characters.

function validate(password) {
  return  /[a-z]+/.test(password) && //contains at least one lowercase letter
  /[A-Z]+/.test(password) && //at least one capital letter
  /[0-9]+/.test(password) && //contains at least one number
  /.{6,}/.test(password) && //6 or more chars
  !/[^a-zA-Z0-9]/.test(password); //does not contain non-alphanumeric chars

// this can also be written using "?=" look ahead.
// they are useful when combining different regex filters.
// (i only learned this after I saw the other answers)

function validate(password) {
  return  /^(?=.*[a-z]+)(?=.*[A-Z]+)(?=.*[0-9]+)[a-zA-Z0-9]{6,}$/.test(password); //does not contain non-alphanumeric chars

I also listened to some more coding blocks podcast. This episode is another one about data structures. I really wish they had an audio editor. They all seem nice and have interesting things to say but they take way too long to actually say it. I wish the information density was much higher. Listening to it faster than 1.5x means I miss the technical things that they do occasionally say. I bet it would be nice background noise while I worked, but if I’m trying to focus on it and actively learn it’s not really my first choice.

Tell me what you think.

This site uses Akismet to reduce spam. Learn how your comment data is processed.