Begin a new Kumite
Search
About
  • Filter by Language:
  • Kumite (ko͞omiˌtā) is the practice of taking techniques learned from Kata and applying them through the act of freestyle sparring.

    You can create a new kumite by providing some initial code and optionally some test cases. From there other warriors can spar with you, by enhancing, refactoring and translating your code. There is no limit to how many warriors you can spar with.

    A great use for kumite is to begin an idea for a kata as one. You can collaborate with other code warriors until you have it right, then you can convert it to a kata.

Fundamentals
Strings
Code
Diff
  • public class FizzBuzz
    {
        public string GetOutput(int number) =>
            (number % 3, number % 5) switch
            {
                (0, 0) => "FizzBuzz",
                (0, _) => "Fizz",
                (_, 0) => "Buzz",
                (_, _) => $"{number}"
            };
    }
  • 11 public class FizzBuzz
    2 {
    3 public string GetOutput(int number)
    4 {
    5 var ret = string.Empty;
    6
    7 if (number % 3 == 0)
    8 ret += "Fizz";
    9 if (number % 5 == 0)
    10 ret += "Buzz";
    11
    12 if (ret.Length == 0)
    13 ret = number.ToString();
    14 return ret;
    15 }
    2+{
    3+ public string GetOutput(int number) =>
    4+ (number % 3, number % 5) switch
    5+ {
    6+ (0, 0) => "FizzBuzz",
    7+ (0, _) => "Fizz",
    8+ (_, 0) => "Buzz",
    9+ (_, _) => $"{number}"
    10+ };
    1616 }

Recent Moves:

Code
Diff
  • function find_unique_items(array1, array2) 
    {       
           
            var first = [ 1, 2, 3, 4, 5, 6, 7, 8];
            var second = [ 3, 5, 7  ];
            var difference = first.filter(x => second.indexOf(x) === -1);
            console.log(difference);
      return [1,2,4,6,8]
      
            var first = [ 1, 2, 3, 4, 5, 6, 7, 8];
            var second = [ 2,5  ];
            var difference = first.filter(x => second.indexOf(x) === -1);
            console.log(difference);
      return [1,3,4,6,7,8]
      
    }
  • 11 function find_unique_items(array1, array2)
    2{
    3 //Find the unique elements from two arrays
    2+{
    3+
    4+ var first = [ 1, 2, 3, 4, 5, 6, 7, 8];
    5+ var second = [ 3, 5, 7 ];
    6+ var difference = first.filter(x => second.indexOf(x) === -1);
    7+ console.log(difference);
    44 return [1,2,4,6,8]
    9+
    10+ var first = [ 1, 2, 3, 4, 5, 6, 7, 8];
    11+ var second = [ 2,5 ];
    12+ var difference = first.filter(x => second.indexOf(x) === -1);
    13+ console.log(difference);
    14+ return [1,3,4,6,7,8]
    15+
    55 }
Code
Diff
  • public class Kata {
      public static boolean[] populateBathroom(boolean[] urinals, int numOfPeople) {
        return new boolean[] {true, false, true};
      }
    }
  • 11 public class Kata {
    22 public static boolean[] populateBathroom(boolean[] urinals, int numOfPeople) {
    3 // Implement the urinal problem, described as "given x number of people walking
    4 // into a bathroom that contains y number of urinals, describe the optimate
    5 // placement of people so that none is standing next to the other"
    6 // In this case, the urinals are represented by a boolean array with
    7 // true representing a person at a urinal, and false meaning the urinal is empty
    88 return new boolean[] {true, false, true};
    99 }
    1010 }

You can also create RegExp for matching whole email without the need to iterate all chars.

P.S. I got ReferenceError that Test is not defined, thus failed tests

Code
Diff
  • const parse = (value = '') => value.split("").every(letter => new RegExp('[A-Za-z0-9.@]').test(letter));
  • 1const parse = (value = '') => {
    2 // if valid email, return true, else return false
    3 let validEmail;
    4 const validCharacters = ["a","A", "b","B","c","C","d","D","e","E","f","F",
    5 "g","G","h","H","i","I","j","J","k","K","l","L",
    6 "m","M","n","N","o","O","p","P","q","Q","r","R",
    7 "s","S","t","T","u","U","v","V","w","W","x","X",
    8 "y","Y","z","Z","0","1","2","3","4","5","6","7",
    9 "8","9","@","."]
    10 const emailArray = value.split("");
    11 for (let i = 0; i < emailArray.length; i++) {
    12 if (validCharacters.includes(value[i]) == true) {
    13 validEmail = true;
    14 }
    15 else {
    16 validEmail = false;
    17 break;
    18 }
    19 }
    20 return validEmail;
    21}
    1+const parse = (value = '') => value.split("").every(letter => new RegExp('[A-Za-z0-9.@]').test(letter));

Recent Moves:

Code
Diff
  • import java.util.Arrays;
    
    interface HighLow {
      static int[] findLargestAndSmallest(int[] nums) {
        if(nums == null || nums.length == 0) return null;
    
        int min = Arrays.stream(nums).min().orElseThrow();
        int max = Arrays.stream(nums).max().orElseThrow();
        return new int[]{min, max};
      }
    }
    
  • 1+import java.util.Arrays;
    2+
    11 interface HighLow {
    2 static int[] findLargestAndSmallest(int[] nums) {
    3 // Change min and max below to be the highest and lowest values
    4 // in the nums array provided to the function
    5 int min = -9;
    6 int max = 9;
    7 return new int[]{min, max};
    8 }
    9
    10 }
    11
    4+ static int[] findLargestAndSmallest(int[] nums) {
    5+ if(nums == null || nums.length == 0) return null;
    1212
    7+ int min = Arrays.stream(nums).min().orElseThrow();
    8+ int max = Arrays.stream(nums).max().orElseThrow();
    9+ return new int[]{min, max};
    10+ }
    1313 }
Code
Diff
  • function prime_checker(n) 
    {
      if(n <= 1)
      {
        return false;
      }
      for(var i = 2; i <= Math.sqrt(n); i++)
      {
        if(n%i == 0)
        {
          return false;
        }
      }
      return true;
    }
  • 1function prime_checker (n) {
    2 // Write a javascript function to check if N is a prime number
    1+function prime_checker(n)
    2+{
    3+ if(n <= 1)
    4+ {
    5+ return false;
    6+ }
    7+ for(var i = 2; i <= Math.sqrt(n); i++)
    8+ {
    9+ if(n%i == 0)
    10+ {
    11+ return false;
    12+ }
    13+ }
    14+ return true;
    33 }
Code
Diff
  • import org.apache.commons.lang3.ArrayUtils;
    
    public class Kata {
        public static int findIndex (int[] array, int target) {
          return ArrayUtils.indexOf(array, target);
        }
    }
  • 1+import org.apache.commons.lang3.ArrayUtils;
    2+
    11 public class Kata {
    2 public static int findIndex (int[] my_array, int t) {
    3 for(int i=0; i< my_array.length; i++){
    4 if(my_array[i]==t){
    5 return i;
    6 }
    7
    8 }
    9 return 4;
    4+ public static int findIndex (int[] array, int target) {
    5+ return ArrayUtils.indexOf(array, target);
    1010 }
    11
    1212 }

Pointers at the beginning and end of our index list (i = 0, j = end of index)
While i is less than j
if there is a mismatch return false !=
if not add i and take away -1 from j until i is equal to or larger than j

Code
Diff
  • public class Kata  {
      public static boolean detectPalindrome(String userWord){
     
            int i = 0, j = userWord.length() - 1;
     
            while (i < j) {
     
                if (userWord.charAt(i) != userWord.charAt(j))
                    return false;
              
                i++;
                j--;
            }
            return true;
        }
      }
  • 1public class Kata {
    2 public static boolean detectPalindrome(String userWord) {
    3 // Detect whether this string is a palindrome
    4 return true;
    1+public class Kata {
    2+ public static boolean detectPalindrome(String userWord){
    3+
    4+ int i = 0, j = userWord.length() - 1;
    5+
    6+ while (i < j) {
    7+
    8+ if (userWord.charAt(i) != userWord.charAt(j))
    9+ return false;
    10+
    11+ i++;
    12+ j--;
    13+ }
    14+ return true;
    15+ }
    55 }
    6}