Write a method named isSubMap
that accepts two hash maps from strings to strings as its parameters and returns true
if every key in the first map is also contained in the second map and maps to the same value in the second map.
For example, given the maps below,
map1
is a sub-map of
map2
, so the call of
isSubMap(map1, map2)
would return
true
.
The order of the parameters does matter, so the call of
isSubMap(map2, map1)
would return
false
.
But map3
is not a sub-map of map2
because the key "Alisha"
is not in map2
and also because the key "Smith"
does not map to the same value as it does in map2
; therefore the call of isSubMap(map3, map2)
would return false
.
The empty map is considered to be a sub-map of every map, so the call of isSubMap(map4, map1)
would return true
.
map1: {Smith=949-0504, Marty=206-9024}
map2: {Marty=206-9024, Hawking=123-4567, Smith=949-0504, Newton=123-4567}
map3: {Alisha=321-7654, Hawking=123-4567, Smith=888-8888}
map4: {}
Constraints: You may not declare any auxiliary data structures in solving this problem.