VOOZH about

URL: https://www.geeksforgeeks.org/javascript/d3-js-d3-ascending-function/

⇱ D3.js | d3.ascending() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

D3.js | d3.ascending() Function

Last Updated : 23 Aug, 2019
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:
Output:
NaN
NaN
0
-1
1
Reference:https://devdocs.io/d3~5/d3-array#ascending
Comment