Skip to content

Instantly share code, notes, and snippets.

@parkerziegler
Created January 30, 2022 18:17
Show Gist options
  • Save parkerziegler/c6c09f18e763b880a3bf57eb6b664e42 to your computer and use it in GitHub Desktop.
Save parkerziegler/c6c09f18e763b880a3bf57eb6b664e42 to your computer and use it in GitHub Desktop.
Get the key of the entry with the maximum value in a Map.
function maxInMap<K>(map: Map<K, number>) {
return [...map.entries()].reduce((acc, el) =>
el[1] > acc[1] ? el : acc
)[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment