I want to create all possible k-element arrays from n-element array. k may be bigger or smaller than n. The elements in the output array don't have to be unique.
For example:
given this array
let a = [1,2]
the function given a desired size 3, should return :
[1,1,1]
[2,1,1]
[1,2,1]
[1,1,2]
[2,2,1]
[2,1,2]
[1,2,2]
[2,2,2]
example 2
given this array
let b = [[0,1], [2,3]]
the function given a desired size 3, should return :
[[0,1], [0,1], [0,1]]
[[2,3], [0,1], [0,1]]
[[0,1], [2,3], [0,1]]
[[0,1], [0,1], [2,3]]
[[2,3], [2,3], [0,1]]
[[2,3], [0,1], [2,3]]
[[0,1], [2,3], [2,3]]
[[2,3], [2,3], [2,3]]
How to do that in Swift?
kmaybe be bigger thann, and the elements in the output array don't have to be unique