I'm trying to figure out how to convert the following javascript function into a dynamic function that will perform the flapMap recursively.
function getPermutations(object) {
let array1 = object[0].options,
array2 = object[1].options,
array3 = object[2].options;
return array1.flatMap(function(array1_item) {
return array2.flatMap(function(array2_item) {
return array3.flatMap(function(array3_item) {
return array1_item + ' ' + array2_item + ' ' + array3_item;
});
});
});
}
let object = [{
"options": ['blue', 'gray', 'green']
}, {
"options": ['large', 'medium', 'small']
}, {
"options": ['wood', 'steel', 'pastic']
}];
console.log('Permutations', getPermutations(object));
In the example, I'm sending 3 arrays into the function which is why it has 3 iterations of flapMap. Works fine, but I am trying to make it dynamic, so I can pass a dynamic array and the function would do the flapMap recursively depending on the array.