Let’s say I have an array of integers in Ruby:
a = [1, 4, 4, 4, -1, 10]
I can find an index of an element by calling:
a.index(4)
However, calling this would return me 1, the lowest index of the element.
What is the best and most efficient way to return the highest element? (in the example above it is 3).
Thanks.
You can use rindex: