Skip to content

Commit

Permalink
Implement rockPaperScissorsII.js
Browse files Browse the repository at this point in the history
  • Loading branch information
fay-jai committed Jan 4, 2015
1 parent 4207aa7 commit a08db00
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions rockPaperScissorsII/rockPaperScissors.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@
*
*/

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

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

previous = rockPaperScissors( n - 1 );
previous.forEach(function (array) {
choices.forEach(function (choice) {
result.push( Array.prototype.concat( array, choice ) );
});
});

return result;
};

0 comments on commit a08db00

Please sign in to comment.