Ruby: How to find the index of the minimum array element?
It would be interesting to read about other situations (finding all and only last minimal element).
ary = [1, 2, 1]# find all matching elements' indexesary.each.with_index.find_all{ |a,i| a == ary.min }.map{ |a,b| b } # => [0, 2]ary.each.with_index.map{ |a, i| (a == ary.min) ? i : nil }.compact # => [0, 2]# find last matching element's indexary.rindex(ary.min) # => 2