Skip to content

Files

Latest commit

 

History

History
133 lines (80 loc) · 2.65 KB

File metadata and controls

133 lines (80 loc) · 2.65 KB

iterCartesianSquare

Create an iterator which generates the Cartesian square of an input array-like object.

Usage

var iterCartesianSquare = require( '@stdlib/iter/cartesian-square' );

iterCartesianSquare( x )

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 );
}

Notes

The function expects only one argument x, an array-like object. The returned iterator will generate all possible combinations from the input array x.

Examples

// 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 ]