Skip to content

TakeSmallestBy

Status: Stable

documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

Description

TakeSmallestBy[list, f, n]

Gives the n elements of list for which f is smallest, in ascending order of f. Over an association, ranks by f of each value.

Examples (3)

Every input below was run against the current Mathilda build and its output recorded.

Basic examples (3)

In[1]:= TakeLargest[{3, 1, 4, 1, 5, 9, 2, 6}, 3]
Out[1]= {9, 6, 5}

In[2]:= TakeLargest[<|"a" -> 3, "b" -> 9, "c" -> 1, "d" -> 6|>, 2]
Out[2]= <|"b" -> 9, "d" -> 6|>

In[3]:= TakeLargestBy[{-9, 2, -3, 5}, Abs, 2]
Out[3]= {-9, 5}

Implementation notes

Attributes: Protected.

References

See also: TakeLargest, TakeSmallest, TakeLargestBy