in reply to Re^2: How to get the index of smallest whole number in an array?
in thread How to get the index of smallest whole number in an array?
Now that you mention it I agree with you, though I have not realised it earlier. Sorting is an overkill when just min value is required. But hey we cover every angle in our homework service :)
In which case your List::Util::reduce solution or a basic min-find will suffice:
$idx = $arr[0]; for(0..$#arr) { $idx = $_ if( ($arr[$idx]<0) || (($arr[$_] >= 0) && ($ +arr[$_] < $arr[$idx])) ) }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How to get the index of smallest whole number in an array?
by AnomalousMonk (Archbishop) on Jul 02, 2018 at 22:46 UTC | |
by bliako (Abbot) on Jul 03, 2018 at 00:02 UTC | |
|
Re^4: How to get the index of smallest whole number in an array?
by Veltro (Hermit) on Jul 03, 2018 at 18:29 UTC | |
by AnomalousMonk (Archbishop) on Jul 03, 2018 at 21:38 UTC |