With the help of d3.permute() method, we can get the array of the values from the source object using specified keys and returns a copy of a permuted array.
Syntax:
d3.permute(source, keys)
Return value: It returns the array of values.
Note: To execute the below examples you have to install the d3 library by using the command prompt for the following command.
npm install d3
Example 1: In this example, we can see that by using d3.permute() method, we are able to get the single array after permutation having values specified in the source array and using keys for the permutation.
Javascript
// Defining d3 contrib variable const d3 = require( 'd3' ); const gfg = d3.permute([1, 2, 3, 4], [3, 2, 1, 0]); console.log(gfg); |
Output:
[ 4, 3, 2, 1 ]
Example 2:
Javascript
// Defining d3 contrib variable const d3 = require( 'd3' ); let gfg = d3.permute ([ "Geeks" , "Geeks" , "for" ], [0, 2, 1]); console.log(gfg); |
Output:
[ 'Geeks', 'for', 'Geeks' ]