{"id":19267019,"url":"https://github.com/mljs/combinations","last_synced_at":"2025-10-29T00:03:12.133Z","repository":{"id":57298962,"uuid":"63785593","full_name":"mljs/combinations","owner":"mljs","description":"Generate all possible unordered samples of size m, without replacement, from a set of n objects","archived":false,"fork":false,"pushed_at":"2018-07-26T07:53:03.000Z","size":274,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-06-19T20:18:57.061Z","etag":null,"topics":["combinations","generation","generators","permutations","statistics"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mljs.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-20T13:55:06.000Z","updated_at":"2020-02-09T02:53:48.000Z","dependencies_parsed_at":"2022-08-26T18:12:41.878Z","dependency_job_id":null,"html_url":"https://github.com/mljs/combinations","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/mljs/combinations","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fcombinations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fcombinations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fcombinations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fcombinations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mljs","download_url":"https://codeload.github.com/mljs/combinations/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fcombinations/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265402833,"owners_count":23759237,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["combinations","generation","generators","permutations","statistics"],"created_at":"2024-11-09T20:09:26.412Z","updated_at":"2025-10-29T00:03:07.097Z","avatar_url":"https://github.com/mljs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# combinations\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![npm download][download-image]][download-url]\n\nGenerate all possible [combinations](https://en.wikipedia.org/wiki/Combination), which are all the unordered samples of size k, without replacement, from a set of n objects. The number of k-combinations is equal to the binomial coefficient:\n\n![image](https://user-images.githubusercontent.com/4118690/40847651-445ec4c2-65bd-11e8-86df-58a5c0f16c73.png)\n\nVery low memory footprint even if the number of combinations to generate is high. Thanks to generators, you can iterate over all possible samples, without creating a very large array.\n\n## Installation\n\n```\n$ npm install ml-combinations\n```\n\n## Usage\n\n```js\n// the package exports a generator function\nconst combinations = require('ml-combinations');\nconst options = { mode: 'index' };\n\n// the generator function returns an iterator\nvar gen = combinations(2, 4, options);\n\n// You can loop thr the iterator\nfor (let combination of gen) {\n  console.log(combination);\n}\n\n// Or use destructuring, if you want to manipulate the array with all possible sample combinations\nconsole.log([...gen]); // [ [ 3, 2 ], [ 0, 2 ], [ 1, 2 ], [ 1, 2 ], [ 0, 2 ], [ 0, 1 ] ]\nconsole.log(Array.from(gen)); // Same thing if destructuring is not supported\n\n// Use mask mode instead of index mode (index mode is the default)\n// The mask mode generates a list of arrays, each of which has a length equal to the number of object\n// Each index has a 0 or 1 to indicate the absence / presence of the object\noptions.mode = 'mask';\ngen = combinations(2, 4, options);\nconsole.log(Array.from(gen)); // [ [ 0, 0, 1, 1 ][ 1, 0, 0, 1 ],[ 0, 1, 0, 1 ],[ 0, 1, 1, 0 ],[ 1, 0, 1, 0 ],[ 1, 1, 0, 0 ] ]\n```\n\n## References\n\nPhillip J Chase, `Algorithm 382: Combinations of M out of N Objects \\[G6\\]',\nCommunications of the Association for Computing Machinery 13:6:368 (1970).\n[To the article](http://dx.doi.org/10.1145/362384.362502)\n\n## License\n\n[MIT](./LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/ml-combinations.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/ml-combinations\n[travis-image]: https://img.shields.io/travis/mljs/combinations/master.svg?style=flat-square\n[travis-url]: https://travis-ci.org/mljs/combinations\n[david-image]: https://img.shields.io/david/mljs/combinations.svg?style=flat-square\n[codecov-url]: https://codecov.io/gh/mljs/combinations\n[codecov-image]: https://img.shields.io/codecov/c/github/mljs/combinations.svg?style=flat-square\n[david-url]: https://david-dm.org/mljs/combinations\n[download-image]: https://img.shields.io/npm/dm/ml-combinations.svg?style=flat-square\n[download-url]: https://npmjs.org/package/ml-combinations\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmljs%2Fcombinations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmljs%2Fcombinations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmljs%2Fcombinations/lists"}