lodash.combinations
Version:
Calculates all possible combinations without repetition of a certain size.
2 lines (1 loc) • 580 B
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("lodash")):"function"==typeof define&&define.amd?define(["lodash"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)._)}(this,(function(e){"use strict";function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=t(e);n.default.mixin({combinations:function(e,t){let f=n.default.values(e);if(f.length<t)return[];let i=(e,t)=>{if(--t<0)return[[]];let n=[];for(e=e.slice();e.length-t;){let f=e.shift();i(e,t).forEach((e=>{e.unshift(f),n.push(e)}))}return n};return i(f,t)}})}));