May 2019
Beginner to intermediate
650 pages
14h 50m
English
For simple ascending and descending sorting order, you can use the native JavaScript sort() method to sort arrays without having to write a comparator function, thus returning one of the two built-in comparators provided in d3-array:
|
Comparator |
Description |
|
d3.ascending(a,b) |
Comparator to sort an array in ascending order. |
|
d3.descending(a,b) |
Comparator to sort an array in descending order. |
The following code examples demonstrate the use of these comparators and the expected results (see Arrays/2-sort.html):
const array = [4,2,9,12,6,23,9,71,55,49];const objects = [{value: 5},{value: 3},{value: 9}]array.sort((a,b) => d3.descending(a,b)); // [71,55,49,23,12,9,9,6,4,2]objects.sort((a,b) ...Read now
Unlock full access