All files / mongoose/lib/helpers each.js

71.42% Statements 10/14
50% Branches 4/8
100% Functions 2/2
71.42% Lines 10/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26    1x 6x       6x 6x 6x 6x 6x     6x         6x 6x          
'use strict';
 
module.exports = function each(arr, cb, done) {
  Iif (arr.length === 0) {
    return done();
  }
 
  let remaining = arr.length;
  let err = null;
  for (const v of arr) {
    cb(v, function(_err) {
      Iif (err != null) {
        return;
      }
      Iif (_err != null) {
        err = _err;
        return done(err);
      }
 
      Eif (--remaining <= 0) {
        return done();
      }
    });
  }
};