Skip to content

Instantly share code, notes, and snippets.

@calexandrepcjr
Created July 2, 2020 15:17
Show Gist options
  • Save calexandrepcjr/9aa9ee1882328f181f6f1c2848a020c9 to your computer and use it in GitHub Desktop.
Save calexandrepcjr/9aa9ee1882328f181f6f1c2848a020c9 to your computer and use it in GitHub Desktop.
A Map with a getByValue routine
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