Ad
Code
Diff
  • function dumbRockPaperScissors(p1, p2) {
      if (p1 === p2) return "Draw";
      
      const con = {
        Scissors: "Paper",
        Rock: "Scissors",
        Paper: "Rock",
      };
      if (p2 === con[p1]) return "Player 1 wins";
      return "Player 2 wins";
      
    }
    • function dumbRockPaperScissors(player1, player2) {
    • if (player1 === player2) return "Draw";
    • function dumbRockPaperScissors(p1, p2) {
    • if (p1 === p2) return "Draw";
    • const condition = {
    • const con = {
    • Scissors: "Paper",
    • Rock: "Scissors",
    • Paper: "Rock",
    • };
    • if (player2 === condition[player1]) return "Player 1 wins";
    • if (p2 === con[p1]) return "Player 1 wins";
    • return "Player 2 wins";
    • }
Strings
Code
Diff
  • isUnique=a=>new Set(a).size===a.length
    • isUnique=s=>new Set(s).size===s.length
    • isUnique=a=>new Set(a).size===a.length
Code
Diff
  • XOR=(b,a)=>!!(b^a)
    • XOR=(a,b)=>!!(a^b)
    • XOR=(b,a)=>!!(b^a)
Code
Diff
  • function dividedByThree(int $number): bool
    {
        if ($number === 0) {return false;}
        return $number % 3 === 0;
    }
    
    • function dividedByThree(int $number): bool
    • {
    • $abs = abs($number);
    • if($abs < 10){
    • return $abs == 3 || $abs == 6 || $abs == 9;
    • }
    • $sum = array_sum(str_split($abs,1));
    • return dividedByThree($sum);
    • if ($number === 0) {return false;}
    • return $number % 3 === 0;
    • }
Code
Diff
  • 
    def colour_of_fruit(fruit):
        #Reds
        if fruit == "Apple": return "Red"
        if fruit == "Raspberry": return "Red"
        if fruit == "Strawberry": return "Red"
        
        #Orange
        if fruit == "Orange": return "Orange"
        
        #Yellows
        if fruit == "Banana": return "Yellow"
        if fruit == "Lemon": return "Yellow"
        if fruit == "Pineapple": return "Yellow"
    
        #Greens
        if fruit == "Avocado": return "Green"
        if fruit == "Lime": return "Green"
        if fruit == "Melon": return "Green"
        if fruit == "Pear": return "Green"
    
        #Blues
        if fruit == "Blueberry": return "Blue"
        if fruit == "Huckleberry": return "Blue"
        
        #Purples
        if fruit == "Plum": return "Purple"
        if fruit == "Grape": return "Purple"
        if fruit == "Maquiberry": return "Purple"
    
        return "Not a fruit!"
    • colour_of_fruit = lambda fruit : {
    • "Apple": "Red", "Raspberry": "Red", "Strawberry": "Red",
    • "Orange": "Orange","Banana": "Yellow", "Lemon": "Yellow",
    • "Pineapple": "Yellow", "Avocado": "Green", "Lime": "Green",
    • "Melon": "Green", "Pear": "Green", "Blueberry": "Blue",
    • "Huckleberry": "Blue", "Plum": "Purple", "Grape": "Purple",
    • "Maquiberry": "Purple"
    • }.get(fruit, "Not a fruit!")
    • def colour_of_fruit(fruit):
    • #Reds
    • if fruit == "Apple": return "Red"
    • if fruit == "Raspberry": return "Red"
    • if fruit == "Strawberry": return "Red"
    • #Orange
    • if fruit == "Orange": return "Orange"
    • #Yellows
    • if fruit == "Banana": return "Yellow"
    • if fruit == "Lemon": return "Yellow"
    • if fruit == "Pineapple": return "Yellow"
    • #Greens
    • if fruit == "Avocado": return "Green"
    • if fruit == "Lime": return "Green"
    • if fruit == "Melon": return "Green"
    • if fruit == "Pear": return "Green"
    • #Blues
    • if fruit == "Blueberry": return "Blue"
    • if fruit == "Huckleberry": return "Blue"
    • #Purples
    • if fruit == "Plum": return "Purple"
    • if fruit == "Grape": return "Purple"
    • if fruit == "Maquiberry": return "Purple"
    • return "Not a fruit!"
Code
Diff
  • public class Kumite {
      public static boolean boolCheck(boolean[] bools) {
        if (bools[0] && bools[1]) return true;
        if (bools[0] && bools[2]) return true;
        if (bools[1] && bools[2]) return true;
        return false;
      }
    }
    • public class Kumite {
    • public static boolean boolCheck(boolean[] bools) {
    • return bools[0] ? bools[1] || bools[2] : bools[1] && bools[2];
    • if (bools[0] && bools[1]) return true;
    • if (bools[0] && bools[2]) return true;
    • if (bools[1] && bools[2]) return true;
    • return false;
    • }
    • }
Code
Diff
  • function relativeNumbers(a, b) {
      let m = Math.min(a, b)**(1/2)
      for (let i = 2; i <= m; i++) {
        //If A and B share a divisor
        if (a % i === 0 && b % i === 0) {
          return "non relative";
        }
      }
      return "relative";
    }
    • function relativeNumbers(a, b) {
    • let arrOne = [];
    • let arrTwo = [];
    • for (let i = 2; i < 10; i++) {
    • if (a % i === 0 && a !== i) {
    • arrOne.push(i);
    • }
    • if(b % i === 0 && b !== i){
    • arrTwo.push(i)
    • }
    • }
    • for(let i = 0; i < arrOne.length; i++){
    • for(let j = 0; j < arrTwo.length; j++){
    • if(arrOne[i] === arrTwo[j]){
    • return "non relative"
    • }else return "relative"
    • let m = Math.min(a, b)**(1/2)
    • for (let i = 2; i <= m; i++) {
    • //If A and B share a divisor
    • if (a % i === 0 && b % i === 0) {
    • return "non relative";
    • }
    • }
    • return "relative";
    • }
Mathematics
Code
Diff
  • function calcTokenCost($price, $token) {
      //Changes the price to be our alt token
      if ($price > 0) {$price = $token * round($price / $token);}
      $res = [$token, $price];
      
      //Grabs the max between the original price and the delimiter
      return max($res);
    }
    • function calcTokenCost($price, $token) {
    • return max($token, $price ? (int) $token * round($price / $token) : 0);
    • //Changes the price to be our alt token
    • if ($price > 0) {$price = $token * round($price / $token);}
    • $res = [$token, $price];
    • //Grabs the max between the original price and the delimiter
    • return max($res);
    • }
Code
Diff
  • package kata
    
    func Multiple3And5(n int) bool {return n%5==0 && n%3==0}
    • package kata
    • func Multiple3And5(n int) bool {
    • return n%15 == 0
    • }
    • func Multiple3And5(n int) bool {return n%5==0 && n%3==0}