Skip to content

Commit 094891e

Browse files
committed
Add pkg to determine array dimensions
1 parent 783eebf commit 094891e

8 files changed

Lines changed: 1111 additions & 0 deletions

File tree

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2018 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# Array Shape
22+
23+
> Determine (nested) array dimensions.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var arrayShape = require( '@stdlib/array/shape' );
41+
```
42+
43+
#### arrayShape( arr )
44+
45+
Returns array dimensions.
46+
47+
```javascript
48+
var arr = [
49+
[ 1, 2, 3 ],
50+
[ 4, 5, 6 ],
51+
[ 7, 8, 9 ]
52+
];
53+
54+
var shape = arrayShape( arr );
55+
// returns [ 3, 3 ]
56+
```
57+
58+
</section>
59+
60+
<!-- /.usage -->
61+
62+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
63+
64+
<section class="notes">
65+
66+
</section>
67+
68+
<!-- /.notes -->
69+
70+
<!-- Package usage examples. -->
71+
72+
<section class="examples">
73+
74+
## Examples
75+
76+
<!-- eslint no-undef: "error" -->
77+
78+
```javascript
79+
var arrayShape = require( '@stdlib/array/shape' );
80+
81+
var shape;
82+
var arr;
83+
84+
arr = [ 1, 2, 3 ];
85+
shape = arrayShape( arr );
86+
// returns [ 3 ]
87+
88+
arr = [
89+
[ 1 ],
90+
[ 2 ],
91+
[ 3 ]
92+
];
93+
shape = arrayShape( arr );
94+
// returns [ 3, 1 ]
95+
96+
arr = [
97+
[],
98+
[],
99+
[]
100+
];
101+
shape = arrayShape( arr );
102+
// returns [ 3, 0 ]
103+
104+
arr = [
105+
[ 1, 2, 3 ]
106+
];
107+
shape = arrayShape( arr );
108+
// returns [ 1, 3 ]
109+
110+
arr = [
111+
[ [ 1 ] ],
112+
[ [ 2 ] ],
113+
[ [ 3 ] ]
114+
];
115+
shape = arrayShape( arr );
116+
// returns [ 3, 1, 1 ]
117+
118+
arr = [ [ [ [ 1, 2, 3 ] ] ] ];
119+
shape = arrayShape( arr );
120+
// returns [ 1, 1, 1, 3 ]
121+
122+
arr = [
123+
[ 1, 2 ],
124+
[ 3, 4 ]
125+
];
126+
shape = arrayShape( arr );
127+
// returns [ 2, 2 ]
128+
129+
arr = [
130+
[ 1, 2, 3 ],
131+
[ 4, 5, 6 ],
132+
[ 7, 8, 9 ]
133+
];
134+
shape = arrayShape( arr );
135+
// returns [ 3, 3 ]
136+
137+
arr = [
138+
[ 1, 2, 3 ],
139+
null,
140+
[ 7, 8, 9 ]
141+
];
142+
shape = arrayShape( arr );
143+
// returns [ 3 ]
144+
145+
arr = [
146+
[ 1, 2, 3 ],
147+
[ [ 4, 5, 6 ] ],
148+
[ [ 7, 8, 9 ] ]
149+
];
150+
shape = arrayShape( arr );
151+
// returns [ 3 ]
152+
153+
arr = [
154+
[ [ 1, 2, 3 ] ],
155+
[ 4, 5, 6 ],
156+
[ [ 7, 8, 9 ] ]
157+
];
158+
shape = arrayShape( arr );
159+
// returns [ 3 ]
160+
161+
arr = [
162+
[ [ 1, 2, 3 ] ],
163+
[ [ 4, 5, 6 ] ],
164+
[ 7, 8, 9 ]
165+
];
166+
shape = arrayShape( arr );
167+
// returns [ 3 ]
168+
169+
arr = [
170+
[ [ [ 1, 2, 3 ] ] ],
171+
[ [ 4, 5, 6 ] ],
172+
[ [ [ 7, 8, 9 ] ] ]
173+
];
174+
shape = arrayShape( arr );
175+
// returns [ 3, 1 ]
176+
```
177+
178+
</section>
179+
180+
<!-- /.examples -->
181+
182+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
183+
184+
<section class="references">
185+
186+
</section>
187+
188+
<!-- /.references -->
189+
190+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
191+
192+
<section class="links">
193+
194+
</section>
195+
196+
<!-- /.links -->

0 commit comments

Comments
 (0)