deno.land / std@0.166.0 / collections / union.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.// This module is browser compatible.
/** * Returns all distinct elements that appear in any of the given arrays * * Example: * * ```ts * import { union } from "https://deno.land/std@$STD_VERSION/collections/union.ts"; * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; * * const soupIngredients = [ 'Pepper', 'Carrots', 'Leek' ] * const saladIngredients = [ 'Carrots', 'Radicchio', 'Pepper' ] * const shoppingList = union(soupIngredients, saladIngredients) * * assertEquals(shoppingList, [ 'Pepper', 'Carrots', 'Leek', 'Radicchio' ]) * ``` */export function union<T>(...arrays: (readonly T[])[]): T[] { const set = new Set<T>();
for (const array of arrays) { for (const element of array) { set.add(element); } }
return Array.from(set);}
std

Version Info

Tagged at
a year ago