Lodash_.xorBy method is similar to the _.xor() method except that it accepts iteratee which is invoked for each element of each array to generate the criterion by which they are compared. Order of result values which is determined by the order they occur in the arrays.
Syntax:
_.xorBy(arrays, iteratee);
Parameters:
- arrays: This parameter holds the arrays to inspect.
- iteratee: This parameter holds the iteratee invoked per element and is invoked with one argument (value).
Return Value:
This method returns the new array of filtered values.
Example 1: In this example, we are using the lodash _.xorBy() method for printing the xor of two arrays having each iteration with Math.floor in the console.
javascript
const _ = require( "lodash" );
let x = _.xorBy([3.1, 1.3, 4.6],
[3.3, 3.4], Math.floor);
let y = _.xorBy([4.1, 2.3, 7.6],
[4.3, 7.4], Math.floor);
let gfg = _.xorBy(x);
let gfg2 = _.xorBy(y);
console.log(gfg);
console.log(gfg2);
|
Output:
[ 1.3, 4.6 ]
[ 2.3 ]
Example 2: In this example, we are using the lodash _.xorBy() method for printing the xor of two arrays in the console.
javascript
const _ = require( "lodash" );
let x = _.xorBy([{ 'x' : 11 }],
[{ 'x' : 12 }, { 'x' : 11 }], 'x' );
let y = _.xorBy([{ 'x' : 11.2 }],
[{ 'x' : 12.2 }, { 'x' : 56.3 },
{ 'x' : 38.21 }, { 'x' : 11.2 }], 'x' );
let gfg = _.xorBy(x);
let gfg3 = _.xorBy(y);
console.log(gfg);
console.log(gfg3);
|
Output:
[ { x: 12 } ]
[ { x: 12.2 }, { x: 56.3 }, { x: 38.21 }]
Example 3: In this example, we are using the lodash _.xorBy() method for printing the xor of two arrays having in the console.
javascript
const _ = require( "lodash" );
let x = _.xorBy([ 'p' ], [ 'q' ,
'r' , 's' , 'p' ]);
let y = _.xorBy([ 'tee' ], [ 'tee' ,
'cee' , 'dee' , 'bee' , 'eee' ]);
let gfg = _.xorBy(x);
let gfg3 = _.xorBy(y);
console.log(gfg);
console.log(gfg3);
|
Output:
['q', 'r', 's' ]
['cee', 'dee', 'bee', 'eee' ]
Note: This code will not work in normal JavaScript because it requires the library lodash to be installed.
Last Updated :
31 Oct, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...