The
d3.ascending() function in D3.js is a built-in comparator function for the natural order which accepts two parameters and computes their natural order.
Syntax:
d3.ascending(x, y)
Parameters: This function accepts two parameters x, y whose natural order needs to be computed.
Return Value: The function has the following return values:
- Returns -1 if the two values are in ascending order.
- Returns 1 if the two values are in descending order.
- Returns 0 if the two values are equal
- Returns NaN if there are no comparable values, i.e. only one or no parameters are passed to the function.
Below programs illustrate the
d3.ascending() function in D3.js.
Example 1:
Output:
-1
1
0
Example 2: