I am trying to make possible cartesian combination from an array of arrays but got stuck at one point. I have an array something like this:
0: ['Blue']
1: ['Small']
var result = values.reduce((a, b) => a.reduce((r, v) => r.concat(b.map(w => [].concat(v, w))), []));
var cartesianProduct = result.map(a => a.join('-'));
with the help of map reduce I am getting the result as: 0: "Blue-Small"
which is not wrong.
but what I want is something like this:
0: ['Blue-Small']
1: ['Small-Blue']
and it should be dynamic. It means if I have an array something like this:
0: ['Blue']
1: ['Small']
2: ['New']
then it should return something like this:
0: ['Blue-Small-New']
1: ['Small-Blue-New']
2: ['New-Small-Blue']
3: ['Blue-New-Small']
4: ['Small-New-Blue']
5: ['New-Blue-Small']
How is it possible to get the result like this