D3.js | d3.permute() function

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.

filter_none

edit
close

play_arrow

link
brightness_4
code

<html>
  
<head>
    <title>
      Getting permuted array of elements
  </title>
</head>
  
<body>
    <script src='https://d3js.org/d3.v4.min.js'>
  </script>
  
    <script>
        // Initialising the arrays of elements
        var Array1 = ["gfg", "Geek", "Geeks", "GeeksforGeeks"];
        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>

chevron_right


Output:

Geek, Geeks, gfg, GeeksforGeeks
abcd, ab, abc, a

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<html>
  
<head>
    <title>
      Getting permuted array of elements
  </title>
</head>
  
<body>
    <script src='https://d3js.org/d3.v4.min.js'>
  </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>

chevron_right


Output:

Hello, Greet, Hi
Hari, Shyam, Geeta, Ram

Ref: https://devdocs.io/d3~4/d3-array#permute



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.