combinate
Version:
Type safe combinatorics utility for getting all combinations.
31 lines (30 loc) • 950 B
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
function combinate(obj) {
var _a;
var combos = [];
for (var key in obj) {
var values = obj[key];
var all = [];
for (var i = 0; i < values.length; i++) {
for (var j = 0; j < (combos.length || 1); j++) {
var newCombo = __assign(__assign({}, combos[j]), (_a = {}, _a[key] = values[i], _a));
all.push(newCombo);
}
}
combos = all;
}
return combos;
}
exports.default = combinate;
;