-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(flatten): update flatted type signature to allow for atleast sin…
…gle level nested sub-arrays
- Loading branch information
1 parent
adc1263
commit 8eb0efc
Showing
2 changed files
with
11 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
import flatten from './flatten' | ||
|
||
describe('Flatten Array (flatten)', () => { | ||
it('Flattens deeply nested sub arrays by default', () => { | ||
it('should flatten deeply nested sub arrays by default', () => { | ||
expect(flatten([[1, [2, [[3]]]], 4, [5, [[[6]]]]])).toEqual([1, 2, 3, 4, 5, 6]) | ||
expect(flatten([1, [2, 3], 4, [5, [6, [7, [8]]]]])).toEqual([1, 2, 3, 4, 5, 6, 7, 8]) | ||
}) | ||
|
||
it('Flattens to a depth level when specified', () => { | ||
it('should flatten to the specified depth level if provided', () => { | ||
const arr = [1, [2, 3], 4, [5, [6, [7]]], 8] | ||
expect(flatten(arr, 1)).toEqual([1, 2, 3, 4, 5, [6, [7]], 8]) | ||
expect(flatten(arr, 2)).toEqual([1, 2, 3, 4, 5, 6, [7], 8]) | ||
}) | ||
|
||
it('Removes empty array items', () => { | ||
it('should remove empty array items', () => { | ||
expect(flatten([1, 2, , 3, , 4, 5, [6, , 7], 8])).toEqual([1, 2, 3, 4, 5, 6, 7, 8]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters