I have an array of n elements and I want to generate all combinations of k elements of that array.
For example: ['a', 'b', 'c']
. If k is 1 then I would have [['a'],['b'], ['c']]
.
If k is 2 then [['a', 'b'], ['a', 'c'], ['b', 'c']]
if k is 3 then [['a', 'b', 'c']]
Thank you in advance
I found an answer using this library https://www.npmjs.com/package/combinations which does exactly what I want.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.