Created
November 11, 2021 17:55
-
-
Save rossja/8eaed9e7aac49f4d7a8c5c035b840e52 to your computer and use it in GitHub Desktop.
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
/** | |
* utils module - provides various utility functions used by the application | |
* @module utils | |
*/ | |
/** | |
* A function to sort an array of indices by a given property | |
* put simply: this lets you sort an array of json objects by | |
* whatever property you tell it to use. | |
* Example: `var teams = data.teams.sort(utils.GetSortOrder("name"))` | |
* @param {string} prop - an index property name | |
* @returns {function} - a function to sort an array of indices by the given property | |
*/ | |
exports.GetSortOrder = function(prop) { | |
return function(a, b) { | |
if (a[prop] > b[prop]) { | |
return 1; | |
} else if (a[prop] < b[prop]) { | |
return -1; | |
} | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment