Logo

Programming-Idioms

History of Idiom 52 > diff from v23 to v24

Edit summary for version 24 by 1.7.4:
New JS implementation by user [1.7.4]

Version 23

2016-11-29, 20:25:36

Version 24

2019-01-24, 09:48:56

Idiom #52 Check if map contains value

Determine whether map m contains an entry with value v, for some key.

Illustration

Idiom #52 Check if map contains value

Determine whether map m contains an entry with value v, for some key.

Illustration
Extra Keywords
table dictionary hash
Extra Keywords
table dictionary hash
Code
Object.values (m).indexOf (v) !== -1
Comments bubble
JavaScript objects are hashmaps.
Object.values converts a hashmap to a list of values.
Array#indexOf finds the first location of a value in an array, or returns -1 if the value isn't in the array.