Logo

Programming-Idioms

History of Idiom 52 > diff from v43 to v44

Edit summary for version 44 by Vaporox:
[JS] Make use of Array.prototype.includes()

Version 43

2020-08-07, 19:30:53

Version 44

2020-08-07, 19:34:44

Idiom #52 Check if map contains value

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

Idiom #52 Check if map contains value

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

Variables
m,v
Variables
m,v
Extra Keywords
table dictionary hash
Extra Keywords
table dictionary hash
Code
Object.values (m).indexOf (v) !== -1
Code
Object.values(m).includes(v)
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.
Comments bubble
JavaScript objects are hashmaps.
Object.values() converts a hashmap to a list of values.
Array#includes then checks whether v is included.