Check whether a map contains a key04.01
contains-key / has-key is a membership test on the key set. It does not look at values. It is expected O(1), the same hash as get.
Use it when you need a boolean, or when get's miss value could collide with a real stored value.
Same skill, three traces. Read all three before you try it.
01present - given
a = [4, 1, 9]as{4:2,1:8,9:3}, has1- walk
key
1- result
- true
02absent - given
a = [4, 1, 9]as{4:2,1:8,9:3}, has8- walk
8is a value- result
- false
03empty - given
a = [], has4- walk
no keys
- result
- false
hasKey(m, k).m is the hash map. k is the key to test.Return true if
k is a key, false if not. Do not look at values. 8 as a value is not a key hit.a = [4, 1, 9] as {4:2,1:8,9:3}, has 1 → true.a = [4, 1, 9] as {4:2,1:8,9:3}, has 8 → false.a = [], has 4 → false.constraintskeys and values are integers. Empty is in the cases.
Every Check with Awel is frozen here. Open one to read the code or load it back into the editor.