D3.js greatest() Method
With the help of d3.greatest() method, we can get the largest value from the sequence of numbers in an array by using this method.
Syntax:
d3.greatest(iterable)
Parameter: This function has the following parameter as mentioned above and described below:
- iterable: Insert any kind of iterable object.
Return Value: It return the largest value.
Note: To execute the below examples you have to install the d3 library by using this command prompt we have to execute the following command.
npm install d3
Example 1: In this example we can see that by using d3.greatest() method, we are able to get the largest value from the sequence from an array by using this method.
Filename: index.js
// Defining d3 contrib variable var d3 = require( 'd3' ); var gfg = d3.greatest([5, 4, 3, 2, 1]) console.log(gfg) |
Output:
5
Example 2: Filename: index.js
// Defining d3 contrib variable var d3 = require( 'd3' ); var arr = [] for ( var i = 0; i < 5; i++) { arr.push(i); } var gfg = d3.greatest(arr) console.log(gfg) |
Output:
4
Note: The above program will compile and run by using the following command:
node index.js
Reference: https://github.com/d3/d3-array/blob/master/README.md
Contact Us