Right now I have
def min(array,starting,ending)
minimum = starting
for i in starting+1 ..ending
if array[i]<array[minimum]
minimum = i
end
end
return minimum
end
Is there a better “implementation” in Ruby? This one still looks c-ish.
Thanks.
If you want to find the index of the minimal element, you can use
Enumerable#enum_fortoget an array of items-index pairs, and find the minimum of those with
Enumerable#min(which will also be the minimum of the original array).If you want to bound it to specific array indices: