title: recursive solution to rock paper scissors
body: <p>we went through this problem in a class today and I'm having trouble visualizing how the recursion is working exactly.  you are supposed to return an array of all possible combinations for n number of rock paper scissors, one player. with n =3, it would return an array of length 27. </p>
  
  <p>I get the roundsLeft-1 parameter in the recursive call, but what's happening each time the function is called? Will really appreciate a high level explanation.  What I think is happening is:</p>
  
  <p>the subroutine recursive function ignores the first element and then concatenates the next two. I'm failing to see how it arrives at all the solutions, and not just the ones with, for example, rock as the first element, and the last two concatenated on. :-/</p>
  
  <pre><code>var rockPaperScissors = function(numRounds) {
    var outcomes = [];
    var plays = ["rock", "paper", "scissors"];
  
    // can add rounds later, get 3 working. 
    // for a three round game, it would be 3^3 = 27.
    // for any number of rounds it would be 3^numrounds. 
  
  function findOutCome(roundsLeft, result){
    // when you cover all the rounds
    // push to the outcomes
    if (roundsLeft === 0) {
      outcomes.push(result);
      return;
    }
  
    plays.forEach(function(play){
      //result.push(play);
      //concat returns the entire array
      findOutCome(roundsLeft-1, result.concat(play))
    })
  }
  
  findOutCome(numRounds, []); // give it a starting point
  
  return outcomes;
  }
  
  
  console.log(rockPaperScissors(3)); // returns an array of length 27
  </code></pre>