Skip to content

Commit 39102f8

Browse files
committed
feat(minimumby): add minimumBy function
1 parent b031d76 commit 39102f8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,14 @@ function internalMinimum<T>(array: ArrayLike<T>, compare: Comparator<T>): T | nu
654654
return result;
655655
}
656656

657+
export function minimumBy<T>(array: ArrayLike<T>, select: (element: T) => number): T | null {
658+
return minimum(array, (a, b) => defaultCompare(select(a), select(b)));
659+
}
660+
661+
export function minimumByFn<T>(select: (element: T) => number): (array: ArrayLike<T>) => T | null {
662+
return array => minimumBy(array, select);
663+
}
664+
657665
export function sum(array: ArrayLike<number>): number {
658666
return fold(array, (a, b) => a + b, 0);
659667
}

0 commit comments

Comments
 (0)