MCPcopy
hub / github.com/Automattic/mongoose / arrayDepth

Function arrayDepth

lib/helpers/arrayDepth.js:5–33  ·  view source on GitHub ↗
(arr)

Source from the content-addressed store, hash-verified

3module.exports = arrayDepth;
4
5function arrayDepth(arr) {
6 if (!Array.isArray(arr)) {
7 return { min: 0, max: 0, containsNonArrayItem: true };
8 }
9 if (arr.length === 0) {
10 return { min: 1, max: 1, containsNonArrayItem: false };
11 }
12 if (arr.length === 1 && !Array.isArray(arr[0])) {
13 return { min: 1, max: 1, containsNonArrayItem: false };
14 }
15
16 const res = arrayDepth(arr[0]);
17
18 for (let i = 1; i < arr.length; ++i) {
19 const _res = arrayDepth(arr[i]);
20 if (_res.min < res.min) {
21 res.min = _res.min;
22 }
23 if (_res.max > res.max) {
24 res.max = _res.max;
25 }
26 res.containsNonArrayItem = res.containsNonArrayItem || _res.containsNonArrayItem;
27 }
28
29 res.min = res.min + 1;
30 res.max = res.max + 1;
31
32 return res;
33}

Callers 2

array.jsFile · 0.85
arrayDepth.test.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…