Start a new Kumite
AllAgda (Beta)BF (Beta)CCFML (Beta)ClojureCOBOL (Beta)CoffeeScriptCommonLisp (Beta)CoqC++CrystalC#D (Beta)DartElixirElm (Beta)Erlang (Beta)Factor (Beta)Forth (Beta)Fortran (Beta)F#GoGroovyHaskellHaxe (Beta)Idris (Beta)JavaJavaScriptJulia (Beta)Kotlinλ Calculus (Beta)LeanLuaNASMNim (Beta)Objective-C (Beta)OCaml (Beta)Pascal (Beta)Perl (Beta)PHPPowerShell (Beta)Prolog (Beta)PureScript (Beta)PythonR (Beta)RacketRaku (Beta)Reason (Beta)RISC-V (Beta)RubyRustScalaShellSolidity (Beta)SQLSwiftTypeScriptVB (Beta)
Show only mine

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.

Ad
Ad
Code
Diff
  • // reescreva em ES6
    function main(a, b = 2, c = 3) {
     return a * b * c
    }
    • // reescreva em ES6
    • function main(a, b, c) {
    • if (typeof b == 'undefined')
    • b = 2;
    • if (typeof c == 'undefined')
    • c = 3
    • return a * b * c;
    • function main(a, b = 2, c = 3) {
    • return a * b * c
    • }

I use this whenever I have to add another directory to my PATH environment variable in my .bashrc. This way I don't have duplicates.

I wrote this years ago and it's hacky and kind of dumb... I'm sure it can be improved.

add_PATH() {
        oIFS=$IFS
        IFS=':'
        t=(${PATH})
        unset IFS
        t=("$1" ${t[@]%%"$1"})
        # output the new array
        IFS=':'
        echo -n "${t[*]}"
        unset t
        IFS=$oIFS
}

echo "Original Path: $PATH"
export PATH=$(add_PATH /usr/local/bin)
echo "New Path: $PATH"
Metaprogramming
  • added compile-time template
  • added random test for runtime function
  • replaced x * 2 with x << 1
Code
Diff
  • constexpr int doubleValue(int x) {
        return x << 1;
    }
    
    template<int x> struct Double {
      static constexpr int value = (x << 1);
    };
    • #include<iostream>
    • int doubleValue(int x) {
    • return x * 2;
    • constexpr int doubleValue(int x) {
    • return x << 1;
    • }
    • template<int x> struct Double {
    • static constexpr int value = (x << 1);
    • };
Code
Diff
  • function dumbRockPaperScissors(player1, player2) {
      const OBJECTS = ['Rock', 'Paper', 'Scissors'];
      return player1 === OBJECTS[0] && player2=== OBJECTS[0] || 
        player1 === OBJECTS[1] && player2=== OBJECTS[1] ||
        player1 === OBJECTS[2] && player2=== OBJECTS[2] ? 'Draw' :
        player1=== OBJECTS[0] && player2=== OBJECTS[1] ||
        player1=== OBJECTS[1] && player2=== OBJECTS[2] ||
        player1=== OBJECTS[2]  && player2=== OBJECTS[0]  ? 'Player 2 wins' :
        'Player 1 wins';
    
    }
    • function dumbRockPaperScissors(player1, player2) {
    • if(player1 == "Rock" && player2 == "Paper"){
    • return "Player 2 wins";
    • }
    • else if(player1 == "Rock" && player2 == "Scissors" ){
    • return "Player 1 wins";
    • }
    • else if(player1 == "Scissors" && player2 == "Paper"){
    • return "Player 1 wins";
    • }
    • else if(player1 == "Scissors" && player2 == "Rock"){
    • return "Player 2 wins";
    • }
    • else if(player1 == "Paper" && player2 == "Scissors"){
    • return "Player 2 wins";
    • }
    • else if(player1 == "Paper" && player2 == "Rock"){
    • return "Player 1 wins";
    • }
    • else if(player1 == "Paper" && player2 == "Paper"){
    • return "Draw";
    • }
    • else if(player1 == "Rock" && player2 == "Rock"){
    • return "Draw";
    • }
    • else if(player1 == "Scissors" && player2 == "Scissors"){
    • return "Draw";
    • }
    • const OBJECTS = ['Rock', 'Paper', 'Scissors'];
    • return player1 === OBJECTS[0] && player2=== OBJECTS[0] ||
    • player1 === OBJECTS[1] && player2=== OBJECTS[1] ||
    • player1 === OBJECTS[2] && player2=== OBJECTS[2] ? 'Draw' :
    • player1=== OBJECTS[0] && player2=== OBJECTS[1] ||
    • player1=== OBJECTS[1] && player2=== OBJECTS[2] ||
    • player1=== OBJECTS[2] && player2=== OBJECTS[0] ? 'Player 2 wins' :
    • 'Player 1 wins';
    • }
Code
Diff
  • const firstNonRepeatingCharacter = (str) => {
        const charCount = {};
    
        for (const char of str) {
            charCount[char] = (charCount[char] || 0) + 1;
        }
        for (const char of str) {
            if (charCount[char] === 1) {
                return char;
            }
        }
        return null;
    };
    • const firstNonRepeatingCharacter = (str) => {
    • for (let i = 0; i < str.length; i++) {
    • let seenDuplicate = false;
    • for (let j = 0; j < str.length; j++) {
    • if (str[i] === str[j] && i !== j) {
    • seenDuplicate = true;
    • break;
    • }
    • }
    • if (!seenDuplicate) {
    • return str[i];
    • const charCount = {};
    • for (const char of str) {
    • charCount[char] = (charCount[char] || 0) + 1;
    • }
    • for (const char of str) {
    • if (charCount[char] === 1) {
    • return char;
    • }
    • }
    • return null; // return null if no unique character is found
    • return null;
    • };
Code
Diff
  • const sum = (a, b) => a+b
    • function sum(a,b) {
    • return a+b; // wrong returning
    • }
    • const sum = (a, b) => a+b
Code
Diff
  • const nums = [
      {0 : "zero"},
      {1 : "one"},
      {2 : "two"},
      {3 : "three"},
      {4 : "four"},
      {5 : "five"},
      {6 : "six"},
      {7 : "seven"},
      {8 : "eight"},
      {9 : "nine"}
    ]
    function digitToText(digit) {
        if(digit > 9 || digit < 0){
            return undefined
        }else{
            return nums[digit][digit]
        }
    }
    • const nums = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
    • const nums = [
    • {0 : "zero"},
    • {1 : "one"},
    • {2 : "two"},
    • {3 : "three"},
    • {4 : "four"},
    • {5 : "five"},
    • {6 : "six"},
    • {7 : "seven"},
    • {8 : "eight"},
    • {9 : "nine"}
    • ]
    • function digitToText(digit) {
    • return nums[digit]
    • if(digit > 9 || digit < 0){
    • return undefined
    • }else{
    • return nums[digit][digit]
    • }
    • }
Code
Diff
  • // # def multiply (a,b):
    // #     return a * b
    
    
    
    const multiply = (a, b) => a * b;
    • // # def multiply (a,b):
    • // # return a * b
    • multiply = (a, b) => a * b;
    • const multiply = (a, b) => a * b;
Code
Diff
  • fn reverse(mut n: u32) -> u32 {
        let mut reversed = 0;
        while n > 0 {
            reversed *= 10;
            reversed += n % 10;
            n /= 10;
        }
        reversed
    }
    
    • public class Algorithms {
    • public static int reverseInt(int n) {
    • int reversed = 0;
    • while(n != 0){
    • reversed = reversed * 10 + (n % 10);
    • n /= 10;
    • fn reverse(mut n: u32) -> u32 {
    • let mut reversed = 0;
    • while n > 0 {
    • reversed *= 10;
    • reversed += n % 10;
    • n /= 10;
    • }
    • return reversed;
    • }
    • }
    • reversed
    • }
Code
Diff
  • #include <vector>
    using namespace std;
    
    int result ( vector <int> sum ) {
      if ( sum.size() == 0 )
        return 0;
      
      int somma_totale = 0;
      for ( int i = 0; i < sum.size(); i++ ) {
        somma_totale = somma_totale + sum[i];
      } return somma_totale;
    }
        
    • def sum(arr):
    • result = 0
    • for i in arr:
    • result += i
    • return result
    • #include <vector>
    • using namespace std;
    • int result ( vector <int> sum ) {
    • if ( sum.size() == 0 )
    • return 0;
    • int somma_totale = 0;
    • for ( int i = 0; i < sum.size(); i++ ) {
    • somma_totale = somma_totale + sum[i];
    • } return somma_totale;
    • }