Skip to content

Plugin for async-chainable to provide Cartesian iteration (all combinations of multiple arrays)

License

Notifications You must be signed in to change notification settings

hash-bang/async-chainable-cartesian

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

async-chainable-cartesian

Plugin for async-chainable to provide Cartesian iteration (all combinations of multiple arrays).

API

product([sets...], callback)

Execute a callback for all permutations of sets.

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 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().

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 for more examples.

About

Plugin for async-chainable to provide Cartesian iteration (all combinations of multiple arrays)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published