I need to make a function that receives an array and generates all combinations based on N param size. Example:
function comb([1,2],3)
out:
[[1,1,1],
[1,1,2],
[1,2,1],
[1,2,2],
[2,1,1],
[2,1,2],
[2,2,1],
[2,2,2]]
or:
function comb([4,1],2)
out:
[[4,4],
[4,1],
[1,4],
[1,1]]