Node JS Cartesian functions are too memory consuming
I’ve made two different functions to calculate all possible combination of elements from n arrays (n not fixed, this is very important to notice) where each array contains a different number of elements (Cartesian product, so in each combo there’s one element from each array). Since these arrays are containing strings, I’ve performed a memory optimization utilizing possible indexes to compute combinations (since saving an integer is much less costly then a string in memory, or at least in most of the cases) and then referenced the combination in this way: combo=[0,1,5,6] => actualCombo=[arrays[0][0],arrays[1][1],arrays[2][5],arrays[3][6]]