JSPM

dimensionality

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q33334F
  • License MIT

Find the number of dimensions of an array

Package Exports

  • dimensionality

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dimensionality) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

dimensionality

Find the number of dimensions of an array

npm install dimensionality --save

Usage

dimensionality(array[, shallowSearch = false])

Returns the maximum array depth of the array, meaning the maximum number of nests in the nested arrays.

var dimensionality = require('dimensionality');

dimensionality(undefined) // 0
dimensionality(4) // 0
dimensionality([2, 4, 5, 2]) // 1
dimensionality([undefined, null, 2, {}, 'test']) // 1
dimensionality([undefined, null, 2, {}, 'test', []]) // 2
dimensionality([[{}, ['test']]]) // 3
dimensionality([1, [2, [3, [4]]]]) // 4

// shallowSearch example
dimensionality([[4, [5]]]) // 3
dimensionality([[4, [5]]], true) // 2
dimensionality([
  [[1, 2], [3, 4]],
  [[5, 6], [7, 8]],
], true) // 3

ShallowSearch

By default, shallowSearch = false.

If shallowSearch = true, then dimensionality finds the dimension only searching for the first element of the nested array.

This is useful for large data structures that are known to have equal array depth.