Created
October 29, 2015 01:15
-
-
Save constdrop/0f71b88f91d7c9bdb6e9 to your computer and use it in GitHub Desktop.
max and min of hash's value included in array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ary = [ { a: 1, b: 2, c: 3 }, { b: 3, c: 2 }, { a: 2, c: 4 } ] | |
| key = :a | |
| max = ary.select{ |h| h[key] }.map{ |h| h[key] }.max # => 2 | |
| min = ary.select{ |h| h[key] }.map{ |h| h[key] }.min # => 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment