September 2017
Intermediate to advanced
216 pages
6h 8m
English
Sometimes, you only know the collection values that you don't want. Instead of building negation into your callback functions, you can use the filterNot() method, as follows:
const myMap = Map.of( 'one', 1, 'two', 2, 'three', 3);const myFilter = i => i % 2;const myOddsMap = myMap.filter(myFilter);const myEvensMap = myMap.filterNot(myFilter);console.log('myMap', myMap.toJS());// -> myMap { one: 1, two: 2, three: 3 }console.log('myOddsMap', myOddsMap.toJS());// -> myOddsMap { one: 1, three: 3 }console.log('myEvensMap', myEvensMap.toJS());// -> myEvensMap { two: 2 }
What's nice about having two inverted filter functions such as filter() and filterNot() is that you can create a generic filter function, as we have done here ...
Read now
Unlock full access