Skip to content

Instantly share code, notes, and snippets.

@ChathuraGH
Created December 1, 2023 19:10
Show Gist options
  • Save ChathuraGH/27c6d02c5dd37516a74e2b0df47de6d8 to your computer and use it in GitHub Desktop.
Save ChathuraGH/27c6d02c5dd37516a74e2b0df47de6d8 to your computer and use it in GitHub Desktop.
dict sortObj
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