TiL: Using the max_by method in Ruby
When trying to get an upper or lower value for a certain field in an object can be cumbersome. But when using the max_by method, this can actually be done quite elegantly. For example: persons = [ { "name" => "John McJohnson","age" => 34, "topScoreAtBowling" => 205}, { "name" => "Davey Jones","age" => 304, "topScoreAtBowling" => 300}, { "name" => "Willy Wonka","age" => 50, "topScoreAtBowling" => 200} ] If we had a bowling competition and wanted to see who had the topScoreAtBowling field, rather than looping through the array and looking at each object, we can simply use the max_by command as follows:...