Created
January 30, 2022 18:17
-
-
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.
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
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