javascript - Choosing a value from each of n identical arrays, get all combinations -
let's have 3 identical arrays, each looks this: [1,2,3,4]
.
by choosing value each array, want exhaust combinations, in example, desired result be:
[1,2,3], [1,2,4], [1,3,4],[2,3,4]
order doesnt matter. i'm iterating on every possibility, , that's waaaay slow. thought first doing check make sure iterator greater 1 left of it, in case of 1,4,...
fail because 3rd array doesn't have bigger 4. additionally i'd need check make sure max of each column no greater column length - (# of repeating columns - column position
. example column 2 not exceed 3. think i'm going down rabbit hole.
any clever ways desired result in fewest iterations possible? modifying arrays fair game, too.
Comments
Post a Comment