Created
July 2, 2020 15:17
-
-
Save calexandrepcjr/9aa9ee1882328f181f6f1c2848a020c9 to your computer and use it in GitHub Desktop.
A Map with a getByValue routine
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
export class TSMap<T, K> extends Map<T, K> { | |
public getByValue(value: K): T | undefined { | |
return [...this.entries()] | |
.filter((tuple) => tuple[1] === value) | |
.map(([key]) => key) | |
.pop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment