JavaScript – Map, Reduce, Filter. Functions in JavaScript

One of the New Years Resolutions, if I had one, would have been to learn JS this year. And as far as I am a VBA developer I automatically assume that I know the basics of it. But still, there are some nice things in JS that one can only dream about in VBA. Thus, in this article I have decided to summarize some of them.JS

Let’s start. The nice things for a VBA developer in JS are probably mapping, filtering and reduction. The idea of mapping is to produce something out of an array. E.g. in the example I produce a new array from the squared values of my array. (arr_b) Then I filter the array, getting only each third value in the array (arr_c). In arr_d and arr_e I use reduction. Reduction does not return arrays, thus the naming “arr_d” and “arr_e” is not really a good idea, but I have done it.

To make the article a nicer one, I have decided to add an object with functions – simple_plan. In this object I have two functions, both of which are generating some variables. The “add_one” function also returns “ALE”, so we may see it if we print the function with “document write”. This is what we get from our code:


This is the code itself:

Here comes the code in github. Enjoy it! 😀


Tagged with: , , ,