2.0.8 • Published 4 years ago
xprod v2.0.8
xprod
xprod calculates the cross product of arrays.
Status
| Category | Status |
|---|---|
| Version | |
| Dependencies | |
| Dev dependencies | |
| Build | |
| License |
Installation
$ npm install xprodQuick 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