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
    • function main(a, b=2, c=3) {
    • return a * b * c;
    • }
Code
Diff
  • // Exercício 1
    const titulo = "UOL - O melhor conteúdo";
    
    
    // Exercício 2
    const tags = []
    
    tags.push(...['A', 'B']);
    
    
    // Exercício 3
    let descricao = "Em 1999";
    
    descricao += " em São Paulo";
    
    
    // Exercício 4
    const materia = {titulo: "Barão de Limeira"};
    
    materia.titulo = "Alameda " + materia.titulo;
    
    
    // Exercício 5
    for (let i = 10; i--;) {
      console.log(i);
    }
    
    
    // Exercício 6
    for (const tag of ['A', 'B']) {
      console.log(tag);
    }
    
    
    // Exercício 7
    for (var j = [].length; j--;) {}
    
    if (j === -1) {
      console.log('Não encontrei');
    }
    
    
    // Exercício 8
    let a = 123;
    
    {
      a *= 2;
    }
    
    console.log(a);
    
    
    // Exercício 9
    let state = 'active';
    
    function stop() {
      state = 'paused';
    }
    
    stop();
    
    
    // Exercício 10
    const TRUE = !0;
    • // Exercício 1
    • var titulo = "UOL - O melhor conteúdo";
    • const titulo = "UOL - O melhor conteúdo";
    • // Exercício 2
    • var tags = []
    • const tags = []
    • tags.push(...['A', 'B']);
    • // Exercício 3
    • var descricao = "Em 1999";
    • let descricao = "Em 1999";
    • descricao += " em São Paulo";
    • // Exercício 4
    • var materia = {titulo: "Barão de Limeira"};
    • const materia = {titulo: "Barão de Limeira"};
    • materia.titulo = "Alameda " + materia.titulo;
    • // Exercício 5
    • for (var i = 10; i--;) {
    • for (let i = 10; i--;) {
    • console.log(i);
    • }
    • // Exercício 6
    • for (var tag of ['A', 'B']) {
    • for (const tag of ['A', 'B']) {
    • console.log(tag);
    • }
    • // Exercício 7
    • for (var j = [].length; j--;) {}
    • if (j === -1) {
    • console.log('Não encontrei');
    • }
    • // Exercício 8
    • var a = 123;
    • let a = 123;
    • {
    • a *= 2;
    • }
    • console.log(a);
    • // Exercício 9
    • var state = 'active';
    • let state = 'active';
    • function stop() {
    • state = 'paused';
    • }
    • stop();
    • // Exercício 10
    • var TRUE = !0;
    • const TRUE = !0;
Fundamentals
Arrays
Data Types

Different way wihout using reduce and forEach.

Code
Diff
  • function getSum(array) {
       return eval(array.join("+"))
    }
    • function getSum(array) {
    • //your code
    • return eval(array.join("+"))
    • }
Code
Diff
  • import java.util.*;
    
    class Solution {
    
      public static String largestNumber(final Integer[] nums) {
      
        Arrays.sort(nums, new Comparator<Integer>() {
          
          @Override
          public int compare(final Integer a, final Integer b) {        
            return (""+b+a).compareTo(""+a+b);
          }
          
        });
        
        String result = "";
        for (final Integer num : nums) {
          result += num;
        }
        
        return result;
      }
    }
    • import java.util.*;
    • class Solution {
    • public static String largestNumber(Integer[] nums) {
    • Arrays.sort( nums, new Comparator<Integer>() {
    • public static String largestNumber(final Integer[] nums) {
    • Arrays.sort(nums, new Comparator<Integer>() {
    • @Override
    • public int compare(Integer a, Integer b) {
    • String aStr = a.toString();
    • String bStr = b.toString();
    • return (aStr + bStr).compareTo(bStr + aStr) * -1;
    • public int compare(final Integer a, final Integer b) {
    • return (""+b+a).compareTo(""+a+b);
    • }
    • } );
    • });
    • String result = "";
    • for(Integer num : nums) {
    • result += num.toString();
    • for (final Integer num : nums) {
    • result += num;
    • }
    • return result;
    • }
    • }
Recursion
Algorithms
Computability Theory
Logic
Theoretical Computer Science
Arrays
Data Types
Methods
Functions
Object-oriented Programming
Control Flow
Basic Language Features
Fundamentals
Programming Paradigms
Classes

Array#flip method:

This kumite is a script that "flips" an Array's contents. Rather than simply Array#reverse it. Here's an example:

[1,2,3,[4,5,6],7,8,9].reverse #=> [9,8,7,[4,5,6],3,2,1]
[1,2,3,[4,5,6],7,8,9].flip    #=> [9,8,7,[6,5,4],3,2,1]
 #                                          ^

It's as if you've physically turned around an array. This goes for any smaller arrays within the Array given, so recursion may be on the cards.

I've done a neat little script (If you don't mind me saying!) carrying out this task. Please feel free to refactor, comment and feedback; I find critisism indispensible.

As a sidenote, maybe we could implement this for Hash as well? Maybe {:hello => "world"} should become {"world" => :hello}?

class Array # Opens up the Array class for method creation
  def flip
    result = []
    me = self.reverse # Don't fret, I'll sort the Arrays out!
    
    me.each do |x|
      
      if x.class == Array then result << x.flip # Here's the recursion.
      else result << x
      end
      
    end
    
    return result
  end
end
Code
Diff
  • def Complicated_Greetings(name):
        h=["H","e","l","l","o"]
        c=","
        w=["W","o","r","l","d"]
        e="!"
        k="".join(h)
        if name=="":
            k+=c
            k+=" "
            k+="".join(w)
            k+=e*2
        else:
            k+=" "
            k+=name
        return k
    • def Complicated_Greetings(name):
    • h=["H","e","l","l","o"]
    • c=","
    • w=["W","o","r","l","d"]
    • e="!"
    • k=""
    • for i in h:
    • k+=i
    • k="".join(h)
    • if name=="":
    • k+=c
    • k+=" "
    • for i in w:
    • k+=i
    • k=k+e+e
    • k+="".join(w)
    • k+=e*2
    • else:
    • k+=" "
    • k+=name
    • return k
Code
Diff
  • function rgbToHsv(rgb) {
      let r = rgb[0] / 255, g = rgb[1] / 255, b = rgb[2] / 255;
      const v = Math.max(r, g, b);
      const min = Math.min(r, g, b);
      const delta = v - min;
    
      const s = v === 0 ? 0 : delta / v;
    
      let h = 0;
      if (delta !== 0) {
        if (v === r) {
          h = (g - b) / delta + (g < b ? 6 : 0);
        } else if (v === g) {
          h = (b - r) / delta + 2;
        } else {
          h = (r - g) / delta + 4;
        }
        h /= 6;
        h *= 360;
      }
      return [Math.round(h), Math.round(s * 100), Math.round(v * 100)];
    }
    • function rgbToHsv(rgb) {
    • let r = rgb[0], g = rgb[1], b = rgb[2];
    • const v = Math.max(r, g, b) / 255;
    • if (v == 0) return Array.of(0, 0, 0);
    • r /= v;
    • g /= v;
    • b /= v;
    • const s = 1 - Math.min(r, g, b) / 255;
    • if (s == 0) return Array.of(0, 0, v * 100);
    • r = 255 - (255 - r) / s;
    • g = 255 - (255 - g) / s;
    • b = 255 - (255 - b) / s;
    • const peak = Math.max(r, g, b);
    • let r = rgb[0] / 255, g = rgb[1] / 255, b = rgb[2] / 255;
    • const v = Math.max(r, g, b);
    • const min = Math.min(r, g, b);
    • const delta = v - min;
    • const s = v === 0 ? 0 : delta / v;
    • let h = 0;
    • if (r == peak) h = g < b ? 360 - b * 60 / 255 : g * 60 / 255;
    • else if (g == peak) h = r > b ? 120 - r * 60 / 255 : 120 + b * 60 / 255;
    • else h = r > g ? 240 + r * 60 / 255 : 240 - g * 60 / 255;
    • return Array.of(Math.round(h), Math.round(s * 100), Math.round(v * 100));
    • if (delta !== 0) {
    • if (v === r) {
    • h = (g - b) / delta + (g < b ? 6 : 0);
    • } else if (v === g) {
    • h = (b - r) / delta + 2;
    • } else {
    • h = (r - g) / delta + 4;
    • }
    • h /= 6;
    • h *= 360;
    • }
    • return [Math.round(h), Math.round(s * 100), Math.round(v * 100)];
    • }
Code
Diff
  • function numMinusSeven(num) {
      return Math.ceil(num/7);
    }
    
    • function numMinusSeven(num) {
    • let arr = []
    • while (num > 0) {
    • num -= 7
    • arr.push(num)
    • }
    • return arr.length
    • return Math.ceil(num/7);
    • }
Fundamentals
Games
Code
Diff
  • fn riddle(word: &str) -> usize {
        word.trim_matches(|c: char| !c.is_ascii_alphabetic()).len()
    }
    • def riddle(word):
    • return len(word) - 1
    • fn riddle(word: &str) -> usize {
    • word.trim_matches(|c: char| !c.is_ascii_alphabetic()).len()
    • }