Skip to content

Commit a2369de

Browse files
committed
✨ union
1 parent 68b3045 commit a2369de

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/array/__tests__/union.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { union } from '..'
2+
3+
test('union', () => {
4+
expect(union([], [])).toEqual([])
5+
})
6+
7+
test('union', () => {
8+
expect(union([2, 1, 2], [2, 3], [4])).toEqual([2, 1, 3, 4])
9+
})
10+
11+
test('union', () => {
12+
expect(union([1, 2], [2, 2], [1])).toEqual([1, 2])
13+
})

src/array/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ export * from './pullAt'
2929
export * from './remove'
3030
export * from './take'
3131
export * from './takeRight'
32+
export * from './union'

src/array/union.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const union = (...arr) =>
2+
Array.from(new Set(arr.reduce((acc, x) => [...acc, ...x], [])))

0 commit comments

Comments
 (0)