JSFiddle - React, Tailwind, and code Playground
by antixrist
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.min.js"></script>
JavaScript
var combinationsPrint = function (combinations) {
combinations = (_.isArray(combinations)) ? combinations : [];
var log = [];
log.push(['Count: ', combinations.length].join(''), '');
_.each(combinations, function (combination, index) {
log.push(['length: ', combination.length, '; [', combination.join(', '), ']'].join(''));
});
return log.join('\n');
};
var generate = function (prefix, min, max) {
prefix = prefix || '';
min = min || 0;
max = max || 1;
var arr = new Array(_.random(min, max));
return _.map(arr, function (item, index) {
return prefix + (index +1);
});
};
var one = generate('one-', 3, 3);
var two = generate('two-', 3, 3);
var three = generate('three-', 3, 3);
var four = generate('four-', 3, 3);
var combinations;
/*
// все возможные
combinations = [];
_.each(one, function (itemOne, indexOne) {
combinations.push([itemOne]);
_.each(two, function (itemTwo, indexTwo) {
combinations.push([itemTwo]);
combinations.push([itemOne, itemTwo]);
_.each(three, function (itemThree, indexThree) {
combinations.push([itemThree]);
combinations.push([itemOne, itemThree]);
combinations.push([itemTwo, itemThree]);
combinations.push([itemOne, itemTwo, itemThree]);
_.each(four, function (itemFour, indexFour) {
combinations.push([itemFour]);
combinations.push([itemOne, itemFour]);
combinations.push([itemTwo, itemFour]);
combinations.push([itemThree, itemFour]);
combinations.push([itemOne, itemTwo, itemFour]);
combinations.push([itemOne, itemThree, itemFour]);
combinations.push([itemTwo, itemThree, itemFour]);
combinations.push([itemOne, itemTwo, itemThree, itemFour]);
});
...