a = %w(albatross dog horse)
a.max_by {|x| x.length } #=> "albatross"
如何使用 max_by.with_index
获取最大值的索引(在本例中为 0)?
ruby 1.9.3
最佳答案
a.each_with_index.max_by { |x,i| x.length }.last
关于ruby - 如何在 Ruby 中使用 max_by 和 with_index?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11183537/