‹ Kinyanjui Wangonya

Tags / javascript


I just came across this online HTML to JSX Compiler. If you’re new (or not) to react and you’re still having a little trouble with JSX, I think this tool is great for learning.

In Javascript, code blocks are created using curly braces ({}). For example:

someFunction() {
    // some code here
}

anotherFunction() {
    // some more code here
}

someFunction and anotherFunction are two different code blocks. These two different code blocks could also be considered as two different scopes. What that means is that the variables declared in someFunction only affect that block of code, and those declared in anotherFunction only affect that block of code. They are “scoped” in that sense.

Given that one of the main reason computers were invented was to solve mathematical problems quickly, it is no wonder that all the modern programming languages are so rich in arithmetic-oriented methods. The earliest computers were basically just calculators. (Yes, I’m looking at you Abacus). If you dabble in Javascript (and a little math every now and then), you might find this useful. The very obvious operations like simple addition (+) and subtraction (-) have been omitted. So have more advanced operations.

I’m going to show Javascript implementations of three more sorting algorithms:

  • Quick sort
  • Heap sort
  • Counting sort

Again, this is not intended to be an in-depth explanation on the ins and outs of how the algorithms work and their performance. If you’d rather read about that, here’s a nice resource I found: Sorting Algorithms

I’ve been learning a lot about data structures and algorithms lately and I’ve noticed in my reading that there aren’t a lot of examples showing implementations of algorithms in Javascript. You’ll mostly find examples in Java, Python, C, C++ etc. Maybe there’s a reason for preferring these languages over Javascript? I’m not sure.

In this first part, I’m going to show Javascript implementations of three sorting algorithms:

  • Merge sort
  • Insertion sort
  • Bubble sort

This is not intended to be an in-depth explanation on the ins and outs of how the algorithms work and their performance. If you’d rather read about that, here’s a nice resource I found: Sorting Algorithms

Regular expressions are patterns used to match character combinations in strings. They help us work with strings in a very performant way.

By formulating regex with a special syntax, you can:

  • search text in a string
  • replace substrings in a string
  • extract information from a string

If all this is completely new to you, take a look at the mdn web docs for more info.

For this post, I’ll focus on one of the easier (and very useful) ways you can use regex.

If you’re using an array in your code, chances are, you’ll need to iterate over the values in the array. There’s a couple of ways you can do that, some better and more efficient than others depending on what you want to accomplish.

For this post, I’ll focus on two ways: some() and every().

Arrow functions were introduced in ES6 as a new syntax for writing Javascript functions. Thanks to their short syntax, they encourage the use of small functions, which make code look cleaner (and () => just looks cooler 😄).

This’ll be a quick one.

Say you want to check if a specific element exists in an array. There’s a couple of ways to do that:

« Older posts Newer posts »