D3.js | d3.permute() function
Last Updated :
26 Jun, 2019
The d3.permute() function in D3.js is used to permutate the elements of the given array with a given specified array of indexes and it returns the array containing the corresponding element for each given indexes.
Syntax:
d3.permute(array, Index)
Parameters: This function accepts two parameters which are mentioned above and described below:
- Array: It is the array of elements on which permutation is performed.
- Index: It is the given index which is used to permutate the given array elements and correspondingly returns the elements of the given array into an array.
Return Value: It returns the array of permuted elements.
Below programs illustrate the d3.permute() function in D3.js.
Example 1: In the below code, the permutation is being done on the elements of the given array with a given specified array of indexes and it returns the array containing the corresponding element for each given indexes.
<html>
<head>
<title>
Getting permuted array of elements
</title>
</head>
<body>
</script>
<script>
var Array1 = [ "gfg" , "Geek" , "Geeks" , "GeeksforGeeks" ];
var Array2 = [ "a" , "ab" , "abc" , "abcd" ];
var Index1 = [1, 2, 0, 3];
var Index2 = [3, 1, 2, 0];
A = d3.permute(Array1, Index1);
B = d3.permute(Array2, Index2);
document.write(A + "<br>" );
document.write(B + "<br>" );
</script>
</body>
</html>
|
Output:
Geek, Geeks, gfg, GeeksforGeeks
abcd, ab, abc, a
Example 2:
<html>
<head>
<title>
Getting permuted array of elements
</title>
</head>
<body>
</script>
<script>
A = d3.permute([ "Hi" , "Hello" , "Greet" ], [1, 2, 0]);
B = d3.permute([ "Ram" , "Shyam" , "Geeta" , "Hari" ],
[3, 1, 2, 0]);
document.write(A + "<br>" );
document.write(B + "<br>" );
</script>
</body>
</html>
|
Output:
Hello, Greet, Hi
Hari, Shyam, Geeta, Ram
Ref: https://devdocs.io/d3~4/d3-array#permute
Share your thoughts in the comments
Please Login to comment...