Skip to content

TakeLargestBy

Returns the n largest elements of a list by a key function.

$ wo 'TakeLargestBy[{1, -3, 2, -4, 5}, Abs, 2]'
{5, -4}

The operator form TakeLargestBy[f, n] applies to a list later.

$ wo 'TakeLargestBy[Abs, 2][{-3, 1, -8, 4}]'
{-8, 4}