How to calculate difference between two Maps in ImmutableJS?

2.6k views Asked by At

I have one parent Map and want to divide it with some logic.

let m = Map();
let sub1 = m.filter((el) => el.isFiltered());

How can I get the rest of the Map? I know that I can invert condition inside filter, but I want to know if there is some method which is analogue to _.difference in underscore?

1

There are 1 answers

0
OlliM On BEST ANSWER

You can use groupBy to get both subsets with one iteration round:

let m = Map();
let grouped = m.groupBy((el) => el.isFiltered());
let pass = grouped.get(true)
let fail = grouped.get(false)

Example on jsbin: http://jsbin.com/gavikufefi/edit?js,console