shape method

List shape(
  1. List list
)

The shape of an array is the number of elements in each dimension.

var shape = m2d.shape([[1, 2],[1, 2]]);
print(shape);
//output [2,2]

Implementation

List shape(List list) {
  var _shapeCheck = _checkArray(list);
  if (!_shapeCheck) throw new Exception('Uneven array dimension');
  var result = [];
  for (;;) {
    result.add(list.length);
    if (_isList(list[0])) {
      list = list[0];
    } else {
      break;
    }
  }
  return result;
}