Friday, January 10, 2025
Google search engine
HomeLanguagesJavascriptD3.js quantileSorted() Method

D3.js quantileSorted() Method

With the help of d3.quantileSorted() method, we can get the quantile value of the given array of sorted values by using p as a probability in this method.

Syntax:

d3.quantileSorted(array, p)

Parameter: This function has the following parameter as mentioned above and described below:

  • array: It is an array of values which is passed as parameter.
  • p: It is the quartile range value.

Return Value: It returns the p-quantile of the given sorted array of elements.

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: Filename: index.js

In this example we can see that by using d3.quantileSorted() method, we are able to get the p-quantile value from the given sorted values of an array by using this method.




// Defining d3 contrib variable  
var d3 = require('d3');
  
var arr = [1.21, 1.33, 1.33, 1.34, 1.37, 1.37, 1.38,
1.4, 1.42, 1.43, 1.43, 1.43, 1.44, 1.45, 1.45, 1.45,
1.45, 1.45, 1.45, 1.45]
  
var gfg = d3.quantileSorted(arr, 0.25)
  
console.log(gfg)


Output:

1.37

Example 2: Filename: index.js




// Defining d3 contrib variable  
var d3 = require('d3');
  
var arr = []
for(var i = 0; i < 50; i++) {
    arr.push(i);
}
  
var gfg = d3.quantileSorted(arr, 0.75)
  
console.log(gfg)


Output:

36.75

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments