Post History
Given a non-ragged array (an array where all sub-arrays at a particular level have the same length) of non-negative integers, answer its shape, that is, the length along every dimension. You may as...
Question
code-golf
#2: Post edited
Given a non-ragged array (an array where all sub-arrays at a particular level have the same length), answer its shape, that is, the length along every dimension. You may assume that the given array has at least one empty dimension, and that only the trailing dimension can have length 0.- ### Test cases
- `[]` → `[0]`
- `[0]` → `[1]`
- `[[]]` → `[1,0]`
- `[[],[]]` → `[2,0]`
- `[[4,4],[0,3]]` → `[2,2]`
- `[[[4],[6]]]` → `[1,2,1]`
- `[[[[7],[0]]]]` → `[1,1,2,1]`
- Given a non-ragged array (an array where all sub-arrays at a particular level have the same length) of non-negative integers, answer its shape, that is, the length along every dimension. You may assume that the given array has at least one empty dimension, and that only the trailing dimension can have length 0.
- ### Test cases
- `[]` → `[0]`
- `[0]` → `[1]`
- `[[]]` → `[1,0]`
- `[[],[]]` → `[2,0]`
- `[[4,4],[0,3]]` → `[2,2]`
- `[[[4],[6]]]` → `[1,2,1]`
- `[[[[7],[0]]]]` → `[1,1,2,1]`
#1: Initial revision
Shape of an array
Given a non-ragged array (an array where all sub-arrays at a particular level have the same length), answer its shape, that is, the length along every dimension. You may assume that the given array has at least one empty dimension, and that only the trailing dimension can have length 0. ### Test cases `[]` → `[0]` `[0]` → `[1]` `[[]]` → `[1,0]` `[[],[]]` → `[2,0]` `[[4,4],[0,3]]` → `[2,2]` `[[[4],[6]]]` → `[1,2,1]` `[[[[7],[0]]]]` → `[1,1,2,1]`