filterMap in JavaScript, efficiency for functional programming

filterMap in JavaScript, efficiency for functional programming

All JavaScript developers are awesome and they deserve a brilliant way of filtering and mapping over an array with just one function with a linear complexity O(n) of one run through the array.

All JavaScript developers are awesome and they deserve a brilliant way of filtering and mapping over an array with just one function with a** linear complexity O(n) of one run through the array**.

If you are looking just for the solution, then here is the code for filterMap. Thanks for stopping by.

const filterMap = (checker, mapper, list) =>
    list.reduce(
      (acc, current) => checker(current) ? [...acc, mapper(current)] : acc,
      []
    );

Please notice that the above function is just a one-liner using a JavaScript reduce function . Here is an example of using filterMap :

const myList = [1, 2, 3];
const myChecker = a => a > 1; // filter only numbers larger than 1
const myMapper = a => a + 1; // make all numbers + 1

filterMap(myChecker, myMapper, myList); // => [3, 4]

functional-programming programming javascript front-end-development web-development

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Top 19 Front-End Web Development Tools to Consider in 2020

In this post, we are putting curated list of top tools with key features and download links "Top 19 Front End Web Development Tools to Consider in 2020"

5 JavaScript Projects You Should Build As a Front-End Developer

5 JavaScript Projects You Should Build As a Front-End Developer: Brochure website; A blog template with HTML and CSS; Web application using an API; An eCommerce shopping cart; Personal portfolio

Top 6 Productivity Tools for Front-end Developers

Today I wanted to share with you the tools I daily use to increase my productivity as a front-end developer. 6 tools to increase your productivity as a Front-end developer.

7 Functional Programming Libraries That Extend JavaScript’s Capabilities

7 Functional Programming Libraries That Extend JavaScript’s Capabilities: Underscore.JS; Lodash.JS; Sugar; Lazy.JS; Ramda; Mesh; Ramda. Functional Programming these days is becoming the standard of building maintainable and modern JavaScript applications. I hope the libraries I mentioned in this article will allow you to take advantage of Functional Programming and write cleaner code.

Functional Programming in JavaScript Explained

Functional programming has become a really hot topic in the JavaScript world. You'll learn: what functional programming is, the types of functions there are, the principles of functional programming, and have a deeper understanding of Higher Order functions.