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>         // Initialising the arrays of elements         var Array1 = [ "gfg" , "Geek" , "Geeks" , "neveropen" ];         var Array2 = [ "a" , "ab" , "abc" , "abcd" ];           // Initialising the indexes         var Index1 = [1, 2, 0, 3];         var Index2 = [3, 1, 2, 0];           // Calling to d3.permute() function         A = d3.permute(Array1, Index1);         B = d3.permute(Array2, Index2);           // Getting permuted array of elements         document.write(A + "<br>" );         document.write(B + "<br>" );     </script> </body>   </html> |
Output:
Geek, Geeks, gfg, neveropen abcd, ab, abc, a
Example 2:
<html>   <head>     <title>       Getting permuted array of elements   </title> </head>   <body>   </script>       <script>         // Taking the array of elements and         // indexes as the parameters         // for the function d3.permute()         A = d3.permute([ "Hi" , "Hello" , "Greet" ], [1, 2, 0]);         B = d3.permute([ "Ram" , "Shyam" , "Geeta" , "Hari" ],                        [3, 1, 2, 0]);           // Getting permuted array of elements         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