fazlurr
7/8/2018 - 4:29 PM

JS Create Combinations

JS Create Combinations or Cartesian Product - https://stackoverflow.com/a/50631472/5627904

const result = data.reduce(
    (a, b) => a.reduce(
        (r, v) => r.concat(b.map(w => [].concat(v, w))),
        []
    )
);

var data = [[1, 2], [10, 20], [100, 200, 300]],
    result = data.reduce((a, b) => a.reduce((r, v) => r.concat(b.map(w => [].concat(v, w))), []));

console.log(result.map(a => a.join(' ')));