Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by turnstep (Parson)
on Mar 08, 2001 at 08:06 UTC ( [id://62914]=note: print w/replies, xml ) Need Help??


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

my $max; my $index; my $x = 0; for ( @myarray ) { $index = $x and $max = $_ if !defined $max or $_ > $max; $x++; } print "The winner is element number $index: $myarray[$index]\n";

Replies are listed 'Best First'.
Re: Answer: How can I find the index of the biggest element in an array?
by I0 (Priest) on Mar 15, 2001 at 00:10 UTC
    There's still a bug, if the biggest element is at index 0

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-25 09:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found