How can I efficiently combine multiple arrays and permute them without including any single array itself? Additionally, I need to combine and permute them into 2D/3D/4D-arrays. Any assistance is appreciated.
var arr1 = ['a', 'b'];
var arr2 = ['c'];
var arr3 = ['d', 'e', 'f'];
function permutation (list, n) {
var results = []
function _perm (list, n, res, start) {
if (res.length === n) {
return results.push(res.join(','))
}
if (start === list.length) { return }
_perm(list, n, res.slice(), start + 1)
res.push(list[start])
_perm(list, n, res, start + 1)
}
_perm(list, n, [], 0)
return results.length
}
console.log(permutation(arr3, 2)) // print ["e,f", "d,f", "d,e"]
Update question:
The combination should be permuted in between the arrays but Not include any single array itself. I will also need to combine and permute them into 2D/3D/4D-array respectively.
Thanks for any helps.