2.0.0 • Published 1 year ago

keymbinatorial v2.0.0

Weekly downloads
89
License
BSD-3-Clause
Repository
github
Last release
1 year ago

Keymbinatorial

Version Downloads Build Status Open Issues License

Generates a unique combinations of key values by taking a single value from each keys array

Usage

npm install keymbinatorial
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

npm test

License

Code licensed under the BSD 3-Clause license. See LICENSE file for terms.

2.0.0

1 year ago

1.2.0

3 years ago

1.1.6

3 years ago

1.1.5

5 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.5

7 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago