Javascript Algorithm String rock Paper Scissor permutation

Description

Javascript Algorithm String rock Paper Scissor permutation


var rockPaperPermutation = function(roundCount){
  var plays = ['r', 'p', 's'];
  var results = [];
  var findPerms = function(roundCount, playedSoFar){
    if(roundCount === 0){
      return results.push(playedSoFar);
    }//  www .ja  v a2 s. co m
    for(var i = 0; i < plays.length; i++){
      findPerms(roundCount - 1, playedSoFar + plays[i]);
    }
  };
  findPerms(roundCount, '');
  return roundCount === 0? []: results;
};

console.log(rockPaperPermutation(3));



PreviousNext

Related