Skip to main content

Variable: toMinMaxBy()

const toMinMaxBy: <Value>(fn) => OptionalReducer<MinMax<Value>>

Defined in: statistics.d.ts:545

Returns an optional reducer that finds the MinMax value of the values it receives based on the fn Compare function.

Use when composing reducers. Prefer minMaxBy for direct use on iterables.

Type Parameters

Value

Value

Parameters

fn

Compare<Value>

Returns

OptionalReducer<MinMax<Value>>

Example

console.log(
pipe(
[`sloth`, `more sloth`, `sleep`, `some sloth`],
map(string => [string.length, string]),
reduce(toGrouped(toMinMaxBy((s1, s2) => s1.localeCompare(s2)), toMap())),
),
)
//=> Map(2) {
//=> 5 => { min: 'sleep', max: 'sloth' },
//=> 10 => { min: 'more sloth', max: 'some sloth' }
//=> }

Since

v2.0.0