# How to find the position in original list ranked first by SortBy

SortBy is a wonder and convenient way to sort a list using a list of functions with which ties can be broken.

input = {{x, 0}, {b, 1, 2}, {c, 2}};
SortBy[input, {Length, First}]
(* {{c, 2}, {x, 0}, {b, 1, 2}} *)


However, is there a fast function that will just tell me the position of the element of the input ranked first by SortBy? In the case above, the answer I'm looking for is 3.

I'm looking for a built-in that does this, or a fast function that can get the result for larger (size of ~1000) lists and lots of tie-breaking functions.

• If WRI creates such system functions, it should be called MaxBy and MinBy or FirstBy and LastBy. – David G. Stork Mar 27 '18 at 17:22
• @JasonB. My v11.3 doesn't know of OrderingBy - where is it implemented? – kirma Mar 27 '18 at 17:34
• @DavidG.Stork I don't think those functions (I guess you mean MaximalBy etc.) implement the "tie-breaking" part of the question, which seems either unique to SortBy, or undocumented for other similar functions. Well, unless I'm mistaken. – kirma Mar 27 '18 at 17:37
• @kirma: I'm assuming that the yet-to-be-written function would indeed implement tie-breaking rules. – David G. Stork Mar 27 '18 at 18:02
• @DavidG.Stork Ah! I missed that small "if" there. – kirma Mar 27 '18 at 18:05

Ordering[Through @* {Length, First} /@ input, 1]

• As a further note: I considered implementing a solution with Fold. Transforming input entries to lists which perform tie-breaking directly on sorting-related functions is million times better an approach. – kirma Mar 27 '18 at 18:00