Last active
June 19, 2024 08:29
-
-
Save luislobo14rap/fd4bb19efe489d856065ad412e128fef to your computer and use it in GitHub Desktop.
sort-obj-by.js
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
// sort-obj-by.js v1 | |
function sortObjBy(array, property) { | |
return array.sort(function(a, b) { | |
return a[property] > b[property] ? 1 : -1 | |
}); | |
}; | |
Object.prototype.sortObjBy = function(property) { | |
return sortObjBy(this, property); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment