mergeArray()function
mergeArray(left: ImmutableArray<L>, right: ImmutableArray<R> | ImmutableArray<L>): ImmutableArray<L | R>
| Param | Type | |
|---|---|---|
left | ImmutableArray<L> | The left array to merge into. required |
right | ImmutableArray<R>ImmutableArray<L> | The right array whose unique items are merged in. required |
| Return | |
|---|---|
ImmutableArray<L | R> | Merged array. - Values that appear in both arrays will not be added twice. - Will be left instance if no items were added.- Will be a new merged array otherwise. |
Merge two arrays.
- Values are considered unique so values will not appear twice.
- Arrays have no concept of
deep mergebecause array keys are not stable. - Use an map/object data structure instead for values that need to be deeply mergeable (only use arrays for primitive values).
Examples
mergeArray([1, 2], [2, 3]) // [1, 2, 3]