Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: argmin & argmax

by Roy Johnson (Monsignor)
on May 04, 2005 at 03:42 UTC ( #453806=note: print w/replies, xml ) Need Help??

in reply to argmin & argmax

You can tighten things up a little by initializing with the first element rather than dealing with undef:
sub argmax(&@) { return() unless @_ > 1; my $block = shift; my $index = shift; my $max = $block->($index); for (@_) { my $val = $block->($_); ($max, $index) = ($val, $_) if $val > $max; } return wantarray ? ($index, $max) : $index; }

Caution: Contents may have been coded under pressure.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://453806]
GotToBTru thinks erix & MySql ... talk about a database trigger
[GotToBTru]: wow .. outta votes and it's not even lunchtime yet

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (17)
As of 2017-03-30 15:53 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (360 votes). Check out past polls.