Skip to main content
Go to Latest
function distinctBy
import { distinctBy } from "https://deno.land/std@0.102.0/collections/distinct_by.ts";

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

Example:

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

console.assert(exampleNamesByFirstLetter === [ 'Anna', 'Kim' ])

Parameters

array: Array<T>
selector: Selector<T, D>

Returns

Array<T>