Create an iterator which generates the Cartesian square of an input array-like object.
var iterCartesianSquare = require( '@stdlib/iter/cartesian-square' );
Returns an iterator which generates the Cartesian Square of an input array-like object.
var x = ['a', 'b', 'c'];
var pair;
var cartesianSquare = iterCartesianSquare( x, n );
for ( pair of cartesianSquare ) {
console.log( pair );
}
The function expects only one argument x, an array-like object. The returned iterator will generate all possible combinations from the input array x.
// Example : Generating Cartesian square of an array
var x = [1, 2, 3];
var cartesianSquare = iterCartesianSquare( x );
var pair;
for ( pair of cartesianSquare ) {
console.log( pair );
}
// Output:
// [ 1, 1 ]
// [ 1, 2 ]
// [ 1, 3 ]
// [ 2, 1 ]
// [ 2, 2 ]
// [ 2, 3 ]
// [ 3, 1 ]
// [ 3, 2 ]
// [ 3, 3 ]