Regular Expression in Javascript

/^[A-Z]{6}\d{2}\D\d{2}\D\d{3}\D$/

1. What the hell is that?

Regular Expressions are as usefull as dangerous. If you are a programmer necessarily you will meet them. Over time, you’ll get better at it but they will remain too dangerous!

Sometimes the RegEx (or RE, technical term) may come in handy. But that doesn’t mean that we’ll use it at any time. Understand these and you will level up as programmer. As you undoubtedly realize, RegEx are not exclusive to the hottest language right now: Javascript.

But before figuring out RegEx, we must first understand why we need RegEx …

Continue reading “Regular Expression in Javascript”

Higher Order Functions in Javascript

const powerOf = (exponent) => {
   return num => num ** exponent;
}

1. If you can read this, then you’re able to understand the rest

Higher-order functions are functions that operate on other functions, for example, one of these can take functions as arguments or return another function. We can have three different types of these:

  1. Functions inside functions
  2. Functions that change functions
  3. Function that manage the control flow

Lucky for me, we have here an inner function example inside a mainly function (give a reading to closure). In this example, powerOf requires an ‘exponent‘ parameter and returns an anonymous function. The latter, accept a ‘num‘ parameter which will be multiplied by itself for ‘exponent‘ times (the ** operator was introduced by ECMAScript7).

Take a deep breath …

Continue reading “Higher Order Functions in Javascript”