DEV Community

Discussion on: Washing your code: avoid loops

Collapse
 
samuraiseoul profile image
Sophie The Lionhart

The reduce in your example is bad because it is not a reduce, its should be a map, reduce is for reducing the entirety to one value normally to sum or average or something.

if (!props.item && props.item.details) { return; }
props.item.details.clients.map(function(client) {
    return client.errorConfigurations.map(function(config){
        usedIn : client.client.name,
        errorMessage : config.error.message,
        errorLevel: config.error.level
    });
}).flat(); // I did not test this at all, I take no responsibility for anything

Also using the function(){} syntax is still useful if you give the function a name, helps give it some extra semantics over the use of arrow functions.