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

Re: min and mindex

by rjt (Deacon)
on Nov 06, 2012 at 17:28 UTC ( #1002536=note: print w/replies, xml ) Need Help??

in reply to min and mindex

#!/opt/local/bin/perl use strict; use warnings; use List::MoreUtils qw(firstidx minmax); my @array1 = qw(9 8 7 1 2 3 4 5 6 7); my @array2 = qw(i h g a b c d e f g); my $min = (minmax @array1)[0]; my $mindex = firstidx { $_ eq $min } @array1; print "min = $min, mindex = $mindex, array2[$mindex] = $array2[$mindex +]\n";

This does scan @array1 twice, but that will not be an issue for small arrays, and if you are using the XS version of List::MoreUtils, this implementation may still be faster than rolling your own min/mindex code.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2016-10-25 02:37 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (313 votes). Check out past polls.