September 2017
Intermediate to advanced
216 pages
6h 8m
English
Let's modify our intersection() function so that it works with maps. When we're looking for the intersection of two or more maps, the result should be another map with the intersecting key-value pairs. Here's the new version of intersection():
const intersection = (...maps) => Map(List() .concat(...maps.map(m => m.entrySeq())) .map(List) .countBy(v => v) .toSeq() .filter(v => v === maps.length) .keySeq());
There are three differences between this implementation and the earlier implementation that works with lists:
Read now
Unlock full access