Created
May 26, 2015 02:34
-
-
Save lamchau/7afa72ae669553adca2a 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
function orderByProperty(prop) { | |
var args = [].slice.call(arguments, 1); | |
return function (a, b) { | |
var propA = a[prop]; | |
var propB = b[prop]; | |
var result; | |
if (typeof propA == 'string' || typeof propB == 'string') { | |
result = String(propA).localeCompare(propB); | |
} else { | |
result = propA - propB; | |
} | |
if (result === 0 && arguments.length) { | |
return orderByProperty.apply(null, args)(a, b); | |
} | |
return result; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment