How would one remove duplicates from an unordered Immutable.List()? (without using toJS() or toArray())
e.g.
Immutable.List.of("green", "blue","green","black", "blue")
Try the following: List<String> duplicates = ["a", "c", "a"]; duplicates = duplicates. toSet(). toList();
You can convert it to a Set. A Set is a List with unique values.
Immutable.List.of("green", "blue","green","black", "blue").toSet()
If you need it as list again just convert it back then:
Immutable.List.of("green", "blue","green","black", "blue").toSet().toList()
Update:
It exists a shorter possibility to get unique values:
Immutable.List.of("green", "blue","green","black", "blue").distinct
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With