September 2017
Intermediate to advanced
216 pages
6h 8m
English
Sorting lists is just like sorting native JavaScript arrays, except that you end up with a new list. The sort() method takes a comparator function, which is used to compare two collection values. If you don't provide this argument, the default comparator uses greater than and less than operators since this is the most common way to sort values:
const myList = List.of(2, 1, 4, 3);const mySortedList = myList.sort();console.log('myList', myList.toJS());// -> myList [ 2, 1, 4, 3 ]console.log('mySortedList', mySortedList.toJS());// -> mySortedList [ 1, 2, 3, 4 ]
As you can see, the new list of numbers is created and it is sorted numerically.
Read now
Unlock full access