Skip to main content

Posts

Showing posts with the label Functional programming

Mapping and Filtering Arrays in JavaScript

In this article we will delve into the  map()  and  filter()  array methods available in JavaScript. We will understand their properties, explore a few use-cases, and discuss how they lend to the "functional" aspect of the programming language. We will also write our own implementations of these functions, just to gain a better understanding of how they work under the hood. Properties of   map()  and  filter() Unlike methods like  push()  or  fill() , both  map()  and  filter()  work on a copy of the input array. They can thus be said to be  immutable . This means they do not modify array elements themselves, rather return a new array after processing the original. These methods are also  pure functions , meaning their output depends solely on the input arguments and not on any external side effects. Working with  Array.prototype.map() The map function operates on arrays and takes exactly one param...