# Getting the index of maximum while generating the values with table

Say I am tabling the values of a two variable function using a list of indexes (which I can't assume to be ordered), I'd like to return the index (or the list of indexes) which yield the maximum value(s) for one of the two arguments (supplying the other one externally.

indexes = {1,5,19,3,2,14};
f[x_,y_] := someFunc[x,y];
(* Just a place holder, any function returning integers should do, if there are multiple maxima I'd like a list in return and I'll break ties later. *)
ArgMax[Table[ f[x,y],{x,indexes}]];

• Is MaximalBy the answer? – Kuba May 7 '18 at 11:00
• Ostensibly yes, but in fact my function takes more values. What would be the syntax in that case? Would something like this work? MaximalFunc[list_,y_] := MaximalBy[list,f[y,#2]]; – Three Diag May 7 '18 at 11:17
• Takes them from where? I'd say MaximalBy[indexes, f[#, externalVar, ...]&] – Kuba May 7 '18 at 11:21

As explained by @Kuba in a comment the answer is simply to use MaximalBy[]
OptimalIndexes[y_] = MaximalBy[indexes,f[#,y]&];