Functional programming techniques
Since ES6, JavaScript has made it easier to implement software solutions using FP. Many engine optimizations have been added that allow for better performance when programming JavaScript according to FP principles. Mapping, filtering, reducing and tail-call optimization are some of these techniques.
Map
Map is a higher-order function that allows us to map a callback to each element of a collection. It is particularly useful when translating all elements of an array from one set of values to another. Here is a simple code example:
function myJS() { let array = [1, 2, 3]; let arrayPlusTwo = array.map(current => current + 2); // arrayPlusTwo == [3, 4, 5] }
This technique makes it possible to avoid using structural loops as much as possible when simply modifying the values of an array.
Filter
Filter is a higher-order function that allows us to distinguish and keep only certain elements of a collection based on a Boolean predicate. Of course, filtering...