Created
July 19, 2013 13:36
-
-
Save jackfranklin/6039140 to your computer and use it in GitHub Desktop.
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
# I've got a hash of things, that all contain an object with in them that has a score property. | |
# how to pull out the one with the highest score? | |
things = { | |
:foo => { | |
:score => 50 | |
# other props | |
}, | |
:bar => { | |
:score => 30 | |
# other props | |
}, | |
:baz => { | |
:score => 66 | |
# other props | |
} | |
} |
// array = your array of objects
// o = an object in the array
Math.max.apply(Math,array.map(function(o){return o.y;}))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you probably want to look at Enumerable - http://ruby-doc.org/core-2.0/Enumerable.html#method-i-max