1.2.3 • Published 4 years ago
@drewkimberly/permutations v1.2.3
NodeJS Object Permutations
Function to generate all permutations of data given zero or more arrays associated with properties in an object
Installation
npm install @drewkimberly/permutations
Usage
import {generatePermutations} from "@drewkimbery/permutations";
const obj = {
pilot: ["Han Solo", "Lando Calrissian"],
copilot: ["Chewbacca", "Rey"],
ship: "Falcon",
speed: "1.5c"
};
console.log(generatePermutations(obj));
The above will output:
[
{
"pilot": "Han Solo",
"copilot": "Chewbacca",
"ship": "Falcon",
"speed": "1.5c"
},
{
"pilot": "Han Solo",
"copilot": "Rey",
"ship": "Falcon",
"speed": "1.5c"
},
{
"pilot": "Lando Calrissian",
"copilot": "Chewbacca",
"ship": "Falcon",
"speed": "1.5c"
},
{
"pilot": "Lando Calrissian",
"copilot": "Rey",
"ship": "Falcon",
"speed": "1.5c"
}
]
Performance
Performance starts to tail off as 1,000,000 permutations is closed in on. After that it's quite computationally expensive and you'll quickly run into heap memory issues. Check out the "Performance Testing" test suite (commented out by default) to play around.
Development
Requirements
- NodeJS
Installing Dependencies
npm i
Running Code Lint
npm run check
Running Tests
npm run test
Running the Build process
npm run build
CI/CD
CI/CD is performed with TravisCI. When a tag is pushed Travis will publish the tag to NPM. See travis.yml for details.