2.0.8 • Published 2 years ago

xprod v2.0.8

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

xprod

xprod calculates the cross product of arrays.

Status

CategoryStatus
Versionnpm
DependenciesDavid
Dev dependenciesDavid
BuildGitHub Actions
LicenseGitHub

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
2.0.8

2 years ago

2.0.7

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.6

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

4 years ago

2.0.0

5 years ago

1.0.0

5 years ago

0.0.1

5 years ago