1.2.3 • Published 6 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/permutationsUsage
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 iRunning Code Lint
npm run checkRunning Tests
npm run testRunning the Build process
npm run buildCI/CD
CI/CD is performed with TravisCI. When a tag is pushed Travis will publish the tag to NPM. See travis.yml for details.