@@ -2,34 +2,61 @@ import { describe, it, expect, xit } from '@jest/globals'
22import { flatten } from './flatten-array.ts'
33
44describe ( 'Flatten Array' , ( ) => {
5- it ( 'no nesting' , ( ) => {
5+ it ( 'empty' , ( ) => {
6+ const arr = [ ]
7+ const expected = [ ]
8+ expect ( flatten ( arr ) ) . toEqual ( expected )
9+ } )
10+
11+ xit ( 'no nesting' , ( ) => {
12+ const arr = [ 0 , 1 , 2 ]
613 const expected = [ 0 , 1 , 2 ]
7- expect ( flatten ( [ 0 , 1 , 2 ] ) ) . toEqual ( expected )
14+ expect ( flatten ( arr ) ) . toEqual ( expected )
15+ } )
16+
17+ xit ( 'flattens a nested array' , ( ) => {
18+ const arr = [ [ [ ] ] ]
19+ const expected = [ ]
20+ expect ( flatten ( arr ) ) . toEqual ( expected )
821 } )
922
1023 xit ( 'flattens array with just integers present' , ( ) => {
24+ const arr = [ 1 , [ 2 , 3 , 4 , 5 , 6 , 7 ] , 8 ]
1125 const expected = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ]
12- expect ( flatten ( [ 1 , [ 2 , 3 , 4 , 5 , 6 , 7 ] , 8 ] ) ) . toEqual ( expected )
26+ expect ( flatten ( arr ) ) . toEqual ( expected )
1327 } )
1428
1529 xit ( '5 level nesting' , ( ) => {
30+ const arr = [ 0 , 2 , [ [ 2 , 3 ] , 8 , 100 , 4 , [ [ [ 50 ] ] ] ] , - 2 ]
1631 const expected = [ 0 , 2 , 2 , 3 , 8 , 100 , 4 , 50 , - 2 ]
17- expect ( flatten ( [ 0 , 2 , [ [ 2 , 3 ] , 8 , 100 , 4 , [ [ [ 50 ] ] ] ] , - 2 ] ) ) . toEqual ( expected )
32+ expect ( flatten ( arr ) ) . toEqual ( expected )
1833 } )
1934
2035 xit ( '6 level nesting' , ( ) => {
36+ const arr = [ 1 , [ 2 , [ [ 3 ] ] , [ 4 , [ [ 5 ] ] ] , 6 , 7 ] , 8 ]
2137 const expected = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ]
22- expect ( flatten ( [ 1 , [ 2 , [ [ 3 ] ] , [ 4 , [ [ 5 ] ] ] , 6 , 7 ] , 8 ] ) ) . toEqual ( expected )
38+ expect ( flatten ( arr ) ) . toEqual ( expected )
39+ } )
40+
41+ xit ( 'consecutive null values at the front of the array are omitted from the final result' , ( ) => {
42+ const arr = [ undefined , undefined , 3 ]
43+ const expected = [ 3 ]
44+ expect ( flatten ( arr ) ) . toEqual ( expected )
45+ } )
46+
47+ xit ( 'consecutive null values in the middle of the array are omitted from the final result' , ( ) => {
48+ const arr = [ 1 , undefined , undefined , 4 ]
49+ const expected = [ 1 , 4 ]
50+ expect ( flatten ( arr ) ) . toEqual ( expected )
2351 } )
2452
25- xit ( '6 level nest list with null values' , ( ) => {
53+ xit ( '6 level nest array with null values' , ( ) => {
54+ const arr = [ 0 , 2 , [ [ 2 , 3 ] , 8 , [ [ 100 ] ] , undefined , [ [ undefined ] ] ] , - 2 ]
2655 const expected = [ 0 , 2 , 2 , 3 , 8 , 100 , - 2 ]
27- expect (
28- flatten ( [ 0 , 2 , [ [ 2 , 3 ] , 8 , [ [ 100 ] ] , undefined , [ [ undefined ] ] ] , - 2 ] )
29- ) . toEqual ( expected )
56+ expect ( flatten ( arr ) ) . toEqual ( expected )
3057 } )
3158
32- xit ( 'all values in nested list are null' , ( ) => {
59+ xit ( 'all values in nested array are null' , ( ) => {
3360 const expected : number [ ] = [ ]
3461 expect (
3562 flatten ( [
0 commit comments