0

I'm making a card game and I'd like to get an array of all possible combinations of the cards on the table (including combos that leave cards on the table). So if there were 2 cards on the table it'd return an array like:

buildArray(2) = [
  [0],
  [1],
  [0,1]
]

([0,0] and [1,1] would be impossible and [1,0] would be redundant)

I know I need to use recursion to do so but I've been falling all over it for hours and would love some help at this point.

Another example:

buildArray(3) = [
    [0],
    [1],
    [2],
    [0,1],
    [0,2],
    [1,2],
    [0,1,2]
]
Zong
  • 6,160
  • 5
  • 32
  • 46
okwme
  • 740
  • 1
  • 7
  • 19
  • Have you tried something? – thefourtheye Dec 22 '15 at 01:49
  • i've made about 3 or 4 attempts and each try just gets hairier and hairier. i feel like i'm starting from the wrong direction and i don't think any of my attempts would make the problem easier. – okwme Dec 22 '15 at 01:51
  • Have you checked the console when running this code? You're trying to assign the array to a function call with an argument at the moment which should result into an `Uncaught ReferenceError: Invalid left-hand side in assignment` error – SidOfc Dec 22 '15 at 01:54
  • 1
    I think thats just an example, not a real code – Rainer Plumer Dec 22 '15 at 01:55
  • 1
    Show your attempt(s). – Karoly Horvath Dec 22 '15 at 01:55
  • 1
    If you're interested, the mathematical operation is the power set https://en.wikipedia.org/wiki/Power_set, excluding the empty set – Joseph Young Dec 22 '15 at 01:57

0 Answers0