N
N
nezzard2017-01-21 16:02:58
Node.js
nezzard, 2017-01-21 16:02:58

How to restrict reduce in node.js?

Good afternoon, there is an array which I sort through

result.reduce((lastRequestDone, item) => { 
return lastRequestDone.then(() => somefunc());
})

On arrival, an array of 9 items, limit to 5 cycles, but only if the function is successfully processed, for example, 3 items in a row does not correspond to if, then it must be skipped and as a result 5 values ​​should be returned, excluding elements with errors.
Tried something similar
result.reduce((lastRequestDone, item) => { 
if(result.name !== 'some' && i <= 5){
return lastRequestDone.then(() => somefunc());
}

})

But in the end I got only an error

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
emp1re, 2017-01-25
@emp1re

primitive example -

async.waterfall([
            (callback) => {
           // do something
                if(result.name !== 'some' && i <= 5)  callback(null, data);
                return callback('err');
            },
            (data, callback) => {
            return callback(result.reduce((lastRequestDone, item) => { 
                    return lastRequestDone.then(() => somefunc());
            }));
            }
        ], function(err, result) {
            if (err) return callback(err); 
           // do something
        });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question