Skip to content

Commit

Permalink
feat(minimumBy): add minimumBy function
Browse files Browse the repository at this point in the history
  • Loading branch information
djcsdy committed Jul 12, 2023
1 parent 6cf9184 commit 2b83628
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,16 @@ function internalMinimum<T>(iterable: Iterable<T>, compare: Comparator<T>): T |
return fold1(iterable, (a, e) => (compare(e, a) < 0 ? e : a));
}

export function minimumBy<T>(iterable: Iterable<T>, select: (element: T) => number): T | null {
return minimum(iterable, (a, b) => defaultCompare(select(a), select(b)));
}

export function minimumByFn<T>(
select: (element: T) => number
): (iterable: Iterable<T>) => T | null {
return iterable => minimumBy(iterable, select);
}

export function sum(iterable: Iterable<number>): number {
return fold(iterable, (a, e) => a + e, 0);
}
Expand Down

0 comments on commit 2b83628

Please sign in to comment.