September 2017
Intermediate to advanced
216 pages
6h 8m
English
The nicest part of the implementation strategy that we've been using with lists and maps so far in this chapter is that it's easy to change. With little effort, we were able to make the same intersection() function work with maps. To change the functionality from intersecting collections to finding the difference, we only needed to change the filter() predicate. Let's apply these changes to create a difference() function that works with maps:
const difference = (...maps) => Map(List() .concat(...maps.map(m => m.entrySeq())) .map(List) .countBy(v => v) .filter(v => v < maps.length) .keySeq());
This looks just like the intersection() method that we just implemented for maps. The only change we've made here is to the filter() ...
Read now
Unlock full access