Skip to main content
Go to Latest
function distinctBy
import { distinctBy } from "";

Returns all elements in the given array that produce a distinct value using the given selector, preserving order by first occurrence.


Example 1

import { distinctBy } from "";
import { assertEquals } from "";

const names = ["Anna", "Kim", "Arnold", "Kate"];
const exampleNamesByFirstLetter = distinctBy(names, (it) => it.charAt(0));

assertEquals(exampleNamesByFirstLetter, ["Anna", "Kim"]);


array: Iterable<T>
selector: (el: T) => D