September 2017
Intermediate to advanced
216 pages
6h 8m
English
You can use ordered sets to remove duplicate values and maintain the value insertion order. This means that you can do things such as converting a list to an ordered set, sorting the set, and then converting it back to a list. Examine the following:
const myList = List.of( 1, 3, 1, 2, 3, 4, 1, 5, 2, 4, 6, 1, 5, 2, 7, 1, 8, 3, 7, 1, 4, 2, 8, 9);const myUniqueList = myList .toOrderedSet() .sort() .reverse() .toList();console.log('myList', myList.toJS());// -> myList [ 1, 3, 1, 2, 3, 4, 1, 5, 2, 4, 6,// -> 1, 5, 2, 7, 1, 8, 3, 7, 1, 4, 2,// -> 8, 9 ]console.log('myUniqueList', myUniqueList.toJS());// -> myUniqueList [ 9, 8, 7, 6, 5,// -> 4, 3, 2, 1 ]
The key here is that the list is converted to an ordered set before any sorting ...
Read now
Unlock full access