Collect.js | crossJoin() Method
Collect.js is a fluent and convenient wrapper for working with arrays and objects. The JavaScript array is first transformed into a collection and then the function is applied to the collection.
The crossJoin() method cross joins the collection with an array or collection and return all possible permutations between them.
Installation:
Syntax:
collect(array1).crossJoin(array2)
Parameters: The collect() takes one argument that is converted into the collection and then crossJoin() function also take an array.
Return Value: Returns an array with all possible permutation of between them.
Below example illustrate the crossJoin() method in JavaScript:
Example: Here collect = require(‘collect.js’) is used to import the collect.js library into the file.
const collect = require( 'collect.js' );
let numbers = [1, 2, 3, 4]
let alphabets = [ 'a' , 'b' , 'c' , 'd' ]
const collection = collect(numbers);
const permutations = collection.crossJoin(alphabets)
let arr = permutations.all();
console.log( "Permutations: " , arr);
|
Output
Last Updated :
15 May, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...