Skip to content

Latest commit

 

History

History
83 lines (62 loc) · 2.38 KB

README.md

File metadata and controls

83 lines (62 loc) · 2.38 KB

xprod

xprod calculates the cross product of arrays.

Status

Category Status
Version npm
Dependencies David
Dev dependencies David
Build GitHub Actions
License GitHub

Installation

$ npm install xprod

Quick Start

First you need to add a reference to xprod to your application:

const { xprod } = require('xprod');

If you use TypeScript, use the following code instead:

import { xprod } from 'xprod';

To calculate the cross product of two or more arrays, call the xprod function and provide the arrays as parameter. The cross product is returned as a generator to allow multiplying arbitrarily large arrays:

const result = xprod([
  [ 'linux', 'windows', 'macOS' ],
  [ 'node-10', 'node-12' ]
]);

// Convert the generator to an array for logging.
console.log([...result]);
// => [
//      [ 'linux', 'node-10' ],
//      [ 'linux', 'node-12' ],
//      [ 'windows', 'node-10' ],
//      [ 'windows', 'node-12' ],
//      [ 'macOS', 'node-10' ],
//      [ 'macOS', 'node-12' ],
//    ]

Since the cross product is calculated lazily, this works, too:

const result = xprod([
  new Array(100000).fill('foo'),
  new Array(100000).fill('bar')
]);

Keep in mind that empty arrays in the input will result in an empty output:

const result = xprod([
  new Array(100000).fill('foo'),
  []
]);

// Convert the generator to an array for logging.
console.log([...result]);
// => []

Running quality assurance

To run quality assurance for this module use roboter:

$ npx roboter