Skip to content
Advertisement

Smarter way of using filter and map instead of filter and loop

I want to create a smarter way of coding of the following example. Important is that each loop (for activeFilters) needs to be fully done, before we want to return the filtersTest.

JavaScript

Advertisement

Answer

First of all, it should be clear that createFilters is not going to return the array, but a promise that will eventually resolve to that array.

With that in mind, you can reduce your code a bit, using Promise.all, the ?. operator, destructuring parameters, and shorthand property names in object literals:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement