Algorithm #01 "rock, paper, scissors"

filoscoderΒ·2019λ…„ 11μ›” 22일
0

Toy Algorithm

λͺ©λ‘ 보기
1/7
post-thumbnail

πŸ‡ΊπŸ‡Έ Complete the function that generates every possible sequence of shoots that a player could shot. [ rock / paper / scissors ]

πŸ‡¦πŸ‡· Completa la funcion que genere todas las secuencias posibles de tiros que un jugador pueda tirar. [ piedra / papel / tijera ] (traducido)

πŸ‡°πŸ‡· λ„μ „μžκ°€ 던질 수 μžˆλŠ” λͺ¨λ“  경우의 수λ₯Ό μƒμ‚°ν•˜λŠ” ν•¨μˆ˜μ˜ κΈ°λŠ₯을 μ™„λ£Œν•˜μ„Έμš”. [ κ°€μœ„ / λ°”μœ„ / 보 ] (λ²ˆμ—­)

Example:

Your output should look something like:

// Test
rockPaperScissors();

// Output -> Array of arrays
// All the posible shots
[
  ["rock", "rock", "rock"],
  ["rock", "rock", "paper"],
  ["rock", "rock", "scissors"],
  ["rock", "paper", "rock"]
  //    ...etc...
];

# START [ here ] 🏁

var rockPaperScissors = function(num) {
  var shot = ["rock", "paper", "scissors"];
  // Your CODE
};

// Test
rockPaperScissors();

# Javascript solution πŸ†

  • Run it on your browser console window (F12) πŸ–₯
  • Feel free to COMMENT your preference language solution πŸ‘©β€πŸ‘©β€πŸ‘§β€πŸ‘¦
  • Do your best to complete the problem 🎭
  • if you can't beat this the solution is below 😱

solution πŸ‘‡

.
.
.
.
.
.
.
.
.
.
.

var rockPaperScissors = function() {
  var shot = ["rock", "paper", "scissors"];
  // Your CODE
  let solution = [];

  for (let i = 0; i < shot.length; i++) {
    for (let j = 0; j < shot.length; j++) {
      for (let k = 0; k < shot.length; k++) {
        var temp = [];
        temp.push(shot[i], shot[j], shot[k]);
        solution.push(temp);
      }
    }
  }
    return solution;
};

// Test
console.log(rockPaperScissors());
profile
Never gets bored of making mistakes and wonder why is that

0개의 λŒ“κΈ€