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])) ) }
In reply to Re^3: How to get the index of smallest whole number in an array?
by bliako
in thread How to get the index of smallest whole number in an array?
by sohamsg90
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |