function distinctBy
distinctBy<T, D>(array: Iterable<T>,selector: (el: T) => D): T[]Returns all elements in the given array that produce a distinct value using the given selector, preserving order by first occurrence.
Examples
Example 1
Example 1
import { distinctBy } from "@std/collections/distinct_by"; import { assertEquals } from "@std/assert/assert_equals"; const names = ["Anna", "Kim", "Arnold", "Kate"]; const exampleNamesByFirstLetter = distinctBy(names, (it) => it.charAt(0)); assertEquals(exampleNamesByFirstLetter, ["Anna", "Kim"]);
Type Parameters
TDParameters
Return Type
T[]