Skip to content

Commit

Permalink
Complete rockPaperScissors.js
Browse files Browse the repository at this point in the history
  • Loading branch information
fay-jai committed Jan 1, 2015
1 parent d90452b commit 076f864
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions rockPaperScissors/rockPaperScissors.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@
*
*/

var rockPaperScissors = function () {
// TODO: your solution here
var rockPaperScissors = function (n) {
var result = [];
var choices = ['rock', 'paper', 'scissors'];
var previous;

// base cases
if ( n <= 0 ) return result;
if ( n === 1 ) return [ ['rock'], ['paper'], ['scissors'] ];

previous = rockPaperScissors(n - 1);

// for each array in previous
previous.forEach(function (array) {
// for each choice in choices
choices.forEach(function (choice) {
// concatenate previous array with choice and push to result
result.push( Array.prototype.concat( array, choice ) );
});
});

return result;
};

0 comments on commit 076f864

Please sign in to comment.