Immutable.js lists have a couple of complimentary methods that are handy for checking whether one list is part of another. Using these methods, you can avoid setting up your own elaborate reducing mechanism.
If you want to know that a list belongs to another list, you can use the isSubset()
method:
const myList = List.of( List.of(1, 2, 3), List.of(4, 5, 6), List.of(7, 8, 9) ); const isSubset = List.of(1, 4, 7) .isSubset(myList.flatten()); console.log('isSubset', isSubset); // -> isSubset true
The myList
collection is a list of lists. So once you flatten it, you can pass it to the isSubset()
method when it's called on the list: List.of(1, 4, 7)
. This returns true
because myList
contains each of these values.