Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: How can I find the index of the biggest element in an array?

by GrandFather (Saint)
on May 27, 2007 at 22:53 UTC ( [id://617776]=note: print w/replies, xml ) Need Help??


in reply to How can I find the index of the biggest element in an array?

Given an array @data containing numeric data:

my $idxMax = 0; $data[$idxMax] > $data[$_] or $idxMax = $_ for 1 .. $#data;

is not only compact but, somewhat surprisingly perhaps, comparable in speed to caching $data[$idxMax] as shown in most of the other variants. A cache variant is worth using if an expensive calculation is required in the comparison or a very large array is being processed.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://617776]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-03-29 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found