MCPcopy Create free account
hub / github.com/antfu/utils / uniqueBy

Function uniqueBy

src/array.ts:77–84  ·  view source on GitHub ↗
(array: readonly T[], equalFn: (a: any, b: any) => boolean)

Source from the content-addressed store, hash-verified

75 * @category Array
76 */
77export function uniqueBy<T>(array: readonly T[], equalFn: (a: any, b: any) => boolean): T[] {
78 return array.reduce((acc: T[], cur: any) => {
79 const index = acc.findIndex((item: any) => equalFn(cur, item))
80 if (index === -1)
81 acc.push(cur)
82 return acc
83 }, [])
84}
85
86/**
87 * Get last item

Callers

nothing calls this directly

Calls 1

reduceMethod · 0.80

Tested by

no test coverage detected