Created
April 1, 2012 22:10
-
-
Save tomasdev/2279102 to your computer and use it in GitHub Desktop.
Array of Objects property sort
This file contains 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
/** | |
* @type void as per Array#sort | |
* @see http://jsfiddle.net/tomasdev/ns2wj/ | |
*/ | |
/** @version 1 */ | |
Array.prototype.psort=function(p){p&&this.sort(function(a,b){return(a[p]<b[p]?-1:a[p]>b[p])})}; | |
/** @version 2 */ | |
Array.prototype.psort=function(p,g,u){p&&this.sort(function(a,b){return +((typeof a[p]===u+"")?!g:((typeof b[p]===u+"")?g:((a[p]<b[p])?-1:(a[p]>b[p]))))})}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment