Category Archives for tutorials

Unraveling Map Filter Reduce in Functional JavaScript

Map filter reduce are considered the fundamental functions in functional programming with JavaScript. In the previous post on the JavaScript Map function, we explored the map function in detail. How map works behind the scene, implementing the map function and using map() to create utility functions to make our lives easier.

We also discussed the concept of deep vs shallow copy, the identifying reference and value types, as well as their behavior in JavaScript.

Needless to say, we covered a lot of ground in the last two posts on functional programming. If you have been following through my series on functional programming, give yourself a pat on the back. Great job!

If you don’t know what functional programming is, read an introduction to functional programming before proceeding. I also recommend reading my post on map (link attached in the first sentence of this post) and going through the exercises.

You need to understand how map() and forEach() works on an intimate level to get the most out of this tutorial.Continue reading

Quick Sort Algorithm | Language Agnostic QuickSort Guide

The quick sort algorithm (sometimes known as QuickSort or partition-exchange sort) is a very useful sorting algorithm that employs the divide and conquer approach.

Before proceeding, if you do not understand how the merge sort algorithm works, I recommend reading up on how the merge sort algorithm works before proceeding.

This will help you conceptualize the quick sort much more quickly.

Other topics that will help you conceptualize the quick sort algorithm include a knowledge and understanding of how recursive data structures such as the binary search tree works.

Once again, this post will be language agnostic. I will be writing out the logic in pseudo code so that regardless of programming language, you will be able to follow along.

At the end of this post, the source for the quick sort algorithm will be provided in JavaScript, C++, Java and Python.Continue reading

JavaScript ES6 The Best Parts

JavaScript ES6 has revolutionized the programming language, adding new features that make the language better suited to handling a variety of cases, especially after JavaScript can now be run on the server via Node.js.

For each JavaScript ECMAscript 6 (henceforth, referred to as ES6) features, I will be explaining exactly why I believe that the mentioned feature is a great addition to the language.

For now, I am going start off with 5 features (there are a few more that I want to add to the list, but those will come in the near future).

This post is meant to be a summary of what I think are the best parts of ES6 and a summary of why I think it is. Therefore, unlike most of my other posts, I will not be diving into the specific behavior, theory and idiosyncrasies of each of the features mentioned in this post.

For the aforementioned reason, I would like to point out that this is not a detailed guide on each of these new ES6 features.

Rather, it is a overview of what I think are the best features that were shipped in ES6.

Continue reading

Understanding Recursion in JavaScript with Confidence

Understanding recursion in JavaScript is not only considered difficult, recursive function calls in it of itself have a bad rap to its name. Some people go far as to even dub it as the unnecessarily memory intensive and complex version of a for/while loop. Okay, I may have slightly exaggerated the aforementioned statement. Before proceeding, I want to debunk the following beliefs that

  1. Recursion is impractical.
  2. It is something that I will never fully understand.

First of all, recursion is not impractical. It may be difficult to understand at first, but this is why I wrote this post. To bring clarity to this issue. Recursion is a great way of breaking a big problem into smaller, identical problems. Thus, it brings greater clarity to the readers of the code.

Before proceeding however, I recommend that readers brush up and study the following topics.

  1. The stack data structure.
  2. JavaScript functions.
  3. Variable scope and hoisting.

The language of choice for this tutorial will be JavaScript. On demand, I am also more than happy to write out the source code examples in either Java or C++.


By the end of this post, I hope that the readers will

  • Have a deeper understanding of recursion in JavaScript.
  • Understand cases or problems where a recursive function would be a great tool to use.
  • Utilize recursion to make newly written/existing code more readable.
  • Identify and distinguish between good and bad use of recursion.

Continue reading

Functional Programming JavaScript Map() Function Demystified

Functional programming in JavaScript relies heavily on concepts that are utilized in the built-in map, reduce and filter methods.

Therefore, since these methods are used frequently in modern day JavaScript programming, understanding how they work is of utmost importance, especially if you are concerned about staying relevant in this field.

I believe that if you are fairly new to functional programming, you can learn a lot by simply studying these built in methods.

Why? Because these methods employ the core concepts of functional programming.

In this post, we will specifically be examining and scrutinizing the JavaScript map() method.

By the end of this tutorial, my hope is that you will be able to write your own implementation of the JavaScript map() method. Naturally, you will become much more accustomed to functional programming and also hopefully, learn a thing or two about the JavaScript language as well.

I am going to assume that you know a little about the basics of functional programming.

If not, I recommend reading an introduction to functional programming in JS before proceeding. Because we will be writing some code based off fundamental functional programming concepts.

In this tutorial, I am going to be testing your knowledge at certain points. Of course, I will provide as much background information as needed before throwing you into the pool.

Don’t worry, by the end of this tutorial, you will feel pretty confident about functional programming.

When you first hear the phrase “JavaScript functional programming methods”, what are the methods that first come to mind?

If you are like me, it would probably be along the lines of

  • map
  • filter
  • reduce

Continue reading

Functional Programming in JavaScript – A Brain Friendly Intro

Functional programming has gained a lot of traction in the JavaScript community in the recent years. Why? This is just my personal opinion, but I believe functional programming has become a hot topic for the following reasons.

  • Because code bases are becoming bigger and bigger, stronger emphasis is being placed on writing testable code with predictable outcomes.
  • Lesser likelihood of side-effects enables us to take advantage of multi-core processors.

Therefore, I believe that every serious JavaScript developers need to get this way of thinking under their belt.

As with my other post on Big O Notation and time complexity, I will try and break down the basics of functional programming. I will continue to update this post based off feedback and suggestions, in order to make this as valuable as possible to readers. Therefore, feedback is very much appreciated!

For those that have never dabbled in functional programming, this topic can initially be very hard to understand.

Supposedly, this topic has a steep learning curve.

Therefore, I am going to attempt to explain the concepts of functional programming in the simplest way possible.

Please provide feedback on parts that are difficult to digest. That way, I can update the content so that you, as the reader, get the most out of this tutorial.

With that being said, lets move straight onto the main contents.Continue reading