argmax and argmin (or max_by and min_by) #7430
Labels
area-core-library
SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.
closed-duplicate
Closed in favor of an existing report
type-enhancement
A request for a change that isn't a bug
This issue was originally filed by [email protected]
Link to StackOverflow question:
http://stackoverflow.com/questions/13884666/any-max-and-argmax
I would like Collection#argmax and argmin. Examples of where these might be useful:
final animalNames = ['cat', 'turtle', 'sheep'];
final longest = animalNames.argmax((name) => name.length);
// longest == 'turtle'
final leastHealth = monsters.argmin((monster) => monster.health);
These are the same as Ruby max_by and min_by:
http://ruby-doc.org/core-1.9.3/Enumerable.html#method-i-max_by
They are also very commonly used in mathematics:
http://en.wikipedia.org/wiki/Arg_max
The text was updated successfully, but these errors were encountered: