Created
December 1, 2023 19:10
-
-
Save ChathuraGH/27c6d02c5dd37516a74e2b0df47de6d8 to your computer and use it in GitHub Desktop.
dict sortObj
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
function sortObj(obj) { | |
// Sort object as list based on values | |
return Object.keys(obj).map(k => ([k, obj[k]])).sort((a, b) => (b[1] - a[1])) | |
} | |
//source | |
//https://stackoverflow.com/questions/25500316/sort-a-dictionary-by-value-in-javascript | |
//https://stackoverflow.com/a/74250133/13861187 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment