https://github.com/hash-bang/async-chainable-cartesian
Plugin for async-chainable to provide Cartesian iteration (all combinations of multiple arrays)
https://github.com/hash-bang/async-chainable-cartesian
async-chainable javascript permutation
Last synced: about 1 month ago
JSON representation
Plugin for async-chainable to provide Cartesian iteration (all combinations of multiple arrays)
- Host: GitHub
- URL: https://github.com/hash-bang/async-chainable-cartesian
- Owner: hash-bang
- License: mit
- Created: 2016-10-10T04:39:57.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-10-11T08:11:55.000Z (over 9 years ago)
- Last Synced: 2025-08-09T01:45:02.466Z (7 months ago)
- Topics: async-chainable, javascript, permutation
- Language: JavaScript
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
async-chainable-cartesian
=========================
Plugin for [async-chainable](https://github.com/hash-bang/async-chainable) to provide Cartesian iteration (all combinations of multiple arrays).
API
===
product([sets...], callback)
----------------------------
Execute a callback for all permutations of sets.
```javascript
var asyncChainable = require('async-chainable');
var asyncChainableCartesian = require('async-chainable-cartesian');
var a = ['foo', 'bar', 'baz'];
var b = ['alpha', 'beta', 'gamma'];
asyncChainable()
.use(asyncChainableCartesian)
.product([a, b], function(next, value, index, max) {
console.log('Product', index + '/' + max, '=', value);
next();
})
.end();
```
See [the test kit](test/product.js) for more examples.
compare(set, callback)
----------------------
Execute a callback for all permutations of items within one set.
Unlike `product()` this function assumes that the result is symmetric - i.e. comparing `set[0]` to `set[1]` would return the same result as comparing `set[1]` to `set[0]`. This allows the function to optimize and make fewer loops than `product()` as the number of comparisons decreases for each item rather than remaining linear as with `product()`.
```javascript
asyncChainable()
.use(asyncChainableCartesian)
.set('set', ['foo', 'bar', 'baz'])
.compare('set', function(next, value, index, max) {
// Will output for values [foo,bar], [foo,baz], [bar,baz]
console.log('Comparison', index + '/' + max, value[0], value[1]);
next();
})
.end();
```
See [the test kit](test/compare.js) for more examples.