MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / unionBy

Function unionBy

packages/utilities/src/array.ts:12–25  ·  view source on GitHub ↗
(
  array1: { [key: string]: any }[],
  array2: { [key: string]: any }[],
  param: string
)

Source from the content-addressed store, hash-verified

10}
11
12export function unionBy(
13 array1: { [key: string]: any }[],
14 array2: { [key: string]: any }[],
15 param: string
16) {
17 const ids = array1.map((object) => object[param]);
18 const result = [...array1];
19 array2.forEach((object) => {
20 if (ids.indexOf(object[param]) === -1) {
21 result.push(object);
22 }
23 });
24 return result;
25}

Callers 2

array.test.tsFile · 0.90
addUsersFunction · 0.90

Calls 1

mapMethod · 0.80

Tested by

no test coverage detected