If a is the array, I want a.index(a.max), but something more Ruby-like. It should be obvious, but I’m having trouble finding the answer at so and elsewhere. Obviously, I am new to Ruby.
If a is the array, I want a.index(a.max) , but something more Ruby-like. It
Share
For Ruby 1.8.7 or above:
It does one iteration. Not entirely the most semantic thing ever, but if you find yourself doing this a lot, I would wrap it in an
index_of_maxmethod anyway.