Created
March 29, 2020 18:35
-
-
Save lski/a2e89c06f1fb29ef121cf48d6aa2a2ca to your computer and use it in GitHub Desktop.
Sort Object Properties
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
/** | |
* Does a simple (single level) sort on the properties in an object. | |
* @returns {Map} | |
*/ | |
function sortObjectProps(json) { | |
return Object.keys(json) | |
.sort((a, b) => a >= b) | |
.reduce((accumulator, item) => { | |
accumulator.set(item, json[item]); | |
return accumulator; | |
}, new Map()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment