Skip to content

Commit 628f75d

Browse files
Merge pull request #34 from dvla/feature/adding-browser-drivers-to-open-source-list
Feature/adding browser drivers to open source list
2 parents caab3fb + 69827be commit 628f75d

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

content/open-source/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ This gem encapsulates a way of having a predefined set of properties within a te
5050

5151
Open Source library to apply Royal Mail Rules & Exceptions to PAF (Postcode Address File) addresses when converting to a printable format.
5252

53+
### [dvla-browser-drivers](https://github.com/dvla/dvla-browser-drivers)
54+
55+
This gem has pre-configured browser drivers that you can use out-of-the-box for the development of your automated test suite or application.
56+
5357
# Dynamics 365
5458

5559
### [dataverse-helper](https://github.com/dvla/dataverse-helper)
@@ -60,4 +64,4 @@ This gem helps you integrate with Microsoft Dynamics using Microsoft Dataverse W
6064

6165
### [postman-paf-js](https://github.com/dvla/postman-paf-js)
6266

63-
Open Source library to apply Royal Mail Rules & Exceptions to PAF (Postcode Address File) addresses when converting to a printable format.
67+
Open Source library to apply Royal Mail Rules & Exceptions to PAF (Postcode Address File) addresses when converting to a printable format.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
author: "Tomos Griffiths"
3+
title: "TiL: Using the max_by method in Ruby"
4+
description: "Using max_by to filter out data based on the highest value for a particular field"
5+
draft: false
6+
date: 2025-02-20
7+
tags: ["Ruby", "max_by", "Testing", "Today I Learned"]
8+
categories: ["TIL", "Ruby", "max_by", "Testing"]
9+
ShowToc: true
10+
TocOpen: true
11+
---
12+
13+
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:
14+
15+
```ruby
16+
persons = [
17+
{ "name" => "John McJohnson","age" => 34, "topScoreAtBowling" => 205},
18+
{ "name" => "Davey Jones","age" => 304, "topScoreAtBowling" => 300},
19+
{ "name" => "Willy Wonka","age" => 50, "topScoreAtBowling" => 200}
20+
]
21+
```
22+
23+
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:
24+
25+
```ruby
26+
persons.max_by { |person| person['topScoreAtBowling']} #{"name"=>"Davey Jones", "age"=>304, "topScoreAtBowling"=>300}
27+
```
28+
29+
The resultant object would be returned, and could be processed into their "Hall of Fame"!
30+
31+
## Conclusion
32+
33+
The `max_by` method is very convenient when dealing with a large array of objects, and you are required to find the highest value for a certain field. Alternatively the `min_by` method can be used to find the lower value of a certain field

0 commit comments

Comments
 (0)