peterschussheim
11/1/2016 - 1:17 PM

rockPaperScissors

rockPaperScissors

///rockPaperScissors(2) should return -> [ "rr", "rp", "rs", "pr", "pp", "ps", "sr", "sp", "ss" ]

var rockPaperScissors = function(rounds) {
  var outcomes = [];
  var plays = ['r', 'p', 's'];
  var playedSoFar = [];
	if (rounds === 0) {
        return [];
    }
  var combos = function(roundsToGo) {
    // base case
    if (roundsToGo === 0) {
      outcomes.push(playedSoFar.slice().join(''));
      return;
    }

    for (var i = 0; i < plays.length; i++) {
      playedSoFar.push(plays[i]);
      combos(roundsToGo - 1);
      playedSoFar.pop();
    }
  };
  combos(rounds);
  return outcomes;
};


rockPaperScissors(0);
rockPaperScissors(1)
rockPaperScissors(2);
rockPaperScissors(3);
// rockPaperPermutation :: Number -> [String]
function rockPaperPermutation(roundCount) {
  var actions = ["r", "p", "s"];
  var result = [];
  var temp = [];
  var counter = roundCount - 1;

  // termination case
  if (roundCount === 0) {
    return [];
  }
  var permutation = function(arr) {
      
  }

return result;
};



var round0 = rockPaperPermutation(0)
var round1 = rockPaperPermutation(1) ///["r", "p", "s"]
var round2 = rockPaperPermutation(2) ///[ "rr", "rp", "rs", "pr", "pp", "ps", "sr", "sp", "ss" ]
var round3 = rockPaperPermutation(3)

rockPaperScissors

This Gist was automatically created by Carbide, a free online programming environment.

You can view a live, interactive version of this Gist here.