https://github.com/screwdriver-cd/keymbinatorial
Module that generates the unique combinations of key values by taking a single value from each keys array
https://github.com/screwdriver-cd/keymbinatorial
Last synced: about 1 year ago
JSON representation
Module that generates the unique combinations of key values by taking a single value from each keys array
- Host: GitHub
- URL: https://github.com/screwdriver-cd/keymbinatorial
- Owner: screwdriver-cd
- License: other
- Created: 2016-07-18T18:36:46.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2022-11-21T18:33:29.000Z (over 3 years ago)
- Last Synced: 2024-04-25T23:21:00.570Z (about 2 years ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/keymbinatorial
- Size: 25.4 KB
- Stars: 0
- Watchers: 15
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Keymbinatorial
[![Version][npm-image]][npm-url] ![Downloads][downloads-image] [![Build Status][status-image]][status-url] [![Open Issues][issues-image]][issues-url] ![License][license-image]
> Generates a unique combinations of key values by taking a single value from each keys array
## Usage
```bash
npm install keymbinatorial
```
```js
var keymbinatorial = require('keymbinatorial');
let objectToCombine = {
a: ['a', 'b', 'c'],
c: [1, 2],
e: [{ a: '1'}, {b: '2'}]
};
// combinations will be an array of unique combinations based on each key and the values in the array
let combinations = keymbinatorial(objectToCombine);
console.log(combinations);
/*
will output:
[
{ a: 'a', c: 1, e: { a: '1' } },
{ a: 'a', c: 1, e: { b: '2' } },
{ a: 'a', c: 2, e: { a: '1' } },
{ a: 'a', c: 2, e: { b: '2' } },
{ a: 'b', c: 1, e: { a: '1' } },
{ a: 'b', c: 1, e: { b: '2' } },
{ a: 'b', c: 2, e: { a: '1' } },
{ a: 'b', c: 2, e: { b: '2' } },
{ a: 'c', c: 1, e: { a: '1' } },
{ a: 'c', c: 1, e: { b: '2' } },
{ a: 'c', c: 2, e: { a: '1' } },
{ a: 'c', c: 2, e: { b: '2' } }
]
*/
```
The `keymbinatorial` function takes in an Nx1 object, where N is a set of keys that map to
an array.
For each key in the object, the function builds up a list of objects containing a unique combination
of keys to values in the array.
## Testing
```bash
npm test
```
## License
Code licensed under the BSD 3-Clause license. See LICENSE file for terms.
[npm-image]: https://img.shields.io/npm/v/keymbinatorial.svg
[npm-url]: https://npmjs.org/package/keymbinatorial
[downloads-image]: https://img.shields.io/npm/dt/keymbinatorial.svg
[license-image]: https://img.shields.io/npm/l/keymbinatorial.svg
[issues-image]: https://img.shields.io/github/issues/screwdriver-cd/screwdriver.svg
[issues-url]: https://github.com/screwdriver-cd/screwdriver/issues
[status-image]: https://cd.screwdriver.cd/pipelines/20/badge
[status-url]: https://cd.screwdriver.cd/pipelines/20