Skip to content

Instantly share code, notes, and snippets.

@jackfranklin
Created July 19, 2013 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackfranklin/6039140 to your computer and use it in GitHub Desktop.
Save jackfranklin/6039140 to your computer and use it in GitHub Desktop.
# 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
}
}
@jemgold
Copy link

jemgold commented Jul 19, 2013

you probably want to look at Enumerable - http://ruby-doc.org/core-2.0/Enumerable.html#method-i-max

@benhowdle89
Copy link

// 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