All files / mongoose/lib/helpers arrayDepth.js

78.94% Statements 15/19
64.28% Branches 9/14
100% Functions 1/1
77.77% Lines 14/18

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 27 28 29 30 31 32 33 34    1x     8x 4x   4x     4x       4x   4x 2x 2x     2x     2x     4x 4x   4x    
'use strict';
 
module.exports = arrayDepth;
 
function arrayDepth(arr) {
  if (!Array.isArray(arr)) {
    return { min: 0, max: 0, containsNonArrayItem: true };
  }
  Iif (arr.length === 0) {
    return { min: 1, max: 1, containsNonArrayItem: false };
  }
  Iif (arr.length === 1 && !Array.isArray(arr[0])) {
    return { min: 1, max: 1, containsNonArrayItem: false };
  }
 
  const res = arrayDepth(arr[0]);
 
  for (let i = 1; i < arr.length; ++i) {
    const _res = arrayDepth(arr[i]);
    Iif (_res.min < res.min) {
      res.min = _res.min;
    }
    Iif (_res.max > res.max) {
      res.max = _res.max;
    }
    res.containsNonArrayItem = res.containsNonArrayItem || _res.containsNonArrayItem;
  }
 
  res.min = res.min + 1;
  res.max = res.max + 1;
 
  return res;
}