Created
August 20, 2014 18:45
-
-
Save gamanox/75fe2391fde815f0f298 to your computer and use it in GitHub Desktop.
coffeescript sort object properties by value in descending
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
| 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