Skip to content

Instantly share code, notes, and snippets.

@gamanox
Created August 20, 2014 18:45
Show Gist options
  • Select an option

  • Save gamanox/75fe2391fde815f0f298 to your computer and use it in GitHub Desktop.

Select an option

Save gamanox/75fe2391fde815f0f298 to your computer and use it in GitHub Desktop.
coffeescript sort object properties by value in descending
sortSome = (array)->
#pusharray
pusharray = []
#save the object in an array
for position of array
pusharray.push [
position
array[position]
]
#sort the array by values
pusharray.sort (a, b) ->
#in descending way
b[1] - a[1]
#return te array ordered
pusharray
#you can use this way
sortSome object.properties
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment