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
  • class Component {
      constructor(dom) {
          this.dom = dom;
      }
      
      onCreate() {
        console.log('onCreate from parent class');
        return 'missing';
      }
      
      static on(event, callback) {
        callback();
      }
      
      async emit(event, data) {}
    }
    
    
    
    class Title extends Component {
      onCreate() {
        super.onCreate()
        return 'super!'
      }
    }
    • class Component {
    • constructor(dom) {
    • this.dom = dom;
    • }
    • onCreate() {
    • console.log('onCreate from parent class');
    • return 'missing';
    • }
    • static on(event, callback) {
    • callback();
    • }
    • async emit(event, data) {}
    • }
    • class Title extends Component {
    • onCreate() {
    • super.onCreate()
    • return 'super!'
    • }
    • }
Code
Diff
  • // reescreva usando ES6
    
    const prop = 'myProp';
    
    const obj = {
      [prop]: 123,
      
      myFunc() {
        return this[prop];
      } 
    };
    
    • // reescreva usando ES6
    • var prop = 'myProp';
    • const prop = 'myProp';
    • var obj = {
    • myFunc: function() {
    • const obj = {
    • [prop]: 123,
    • myFunc() {
    • return this[prop];
    • }
    • };
    • obj[prop] = 123;
Code
Diff
  • let results = [
      {materia: {conteudo: {titulo: 'São Paulo'}}, tags: [1, 2, 3]},
      {materia: {conteudo: {}}, tags: [3, 2]},
      {materia: {conteudo: {titulo: 'Rio de Janeiro'}}, tags: [3, 2]},
    ];
    
    
    for (const { materia: { conteudo: {titulo = 'Brasil'}}} of results) {
      console.log(titulo);
    }
    • let results = [
    • {materia: {conteudo: {titulo: 'São Paulo'}}, tags: [1, 2, 3]},
    • {materia: {conteudo: {}}, tags: [3, 2]},
    • {materia: {conteudo: {titulo: 'Rio de Janeiro'}}, tags: [3, 2]},
    • ];
    • for (const result of results) {
    • let titulo = result.materia.conteudo.titulo || 'Brasil';
    • for (const { materia: { conteudo: {titulo = 'Brasil'}}} of results) {
    • console.log(titulo);
    • }
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
    let 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 (let tag of ['A', 'B']) {
      console.log(tag);
    }
    
    
    // Exercício 7
    for (let j = [].length; 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"};
    • let 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 (let tag of ['A', 'B']) {
    • console.log(tag);
    • }
    • // Exercício 7
    • for (var j = [].length; j--;) {}
    • for (let j = [].length; 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;
Utilities

The idea here is to provide the ability to process a batch of callbacks. It provides the following capabilities:

  • dynamic batch list, can be exanded at any time
  • each callback is isolated, if an error is thrown it will not prevent the next callback from being called
  • each callback has a timeout, so that if it does not call the next function itself, it will eventually be called automatically.
  • batches can be ran at intervals, either forever, or up to configured amount of times
  • events are provided to hook into batchStart, batchEnd, error and stopped
  • nextTick can automatically be called for each item within the batch
// interval processor's job is to run a batch of callback items, one at a time. It runs these batches
// at a given interval, and will continue to run batches either forever or until a maxBatches value is reached.
var Processor = function(interval)
{
    this.nextTick = true;
    this.interval = interval;
    this.timeout = 50;
    this.items = [];
    this.maxBatch = null;
    this.events = {error: [], batchStart: [], batchEnd: [], stopped: [], timeout: []};
    console.log('Interval Processor created with ' + interval + 'ms interval');
}

Processor.prototype.on = function on(event, callback)
{
    this.events[event].push(callback);
}

// returns a new function that ensures that the passed in fn only gets called once no matter
// how many times the returned function is called.
function once(fn)
{
    var called = false;
    return function()
    {
        if (!called)
        {
            if (fn) fn();
            called = true;
        }
    }
}

function fire(processor, event, arg)
{
    processor.events[event].forEach(function(fn)
    {
        fn(processor, arg);
    });
}

function nextTick(run)
{
    return function(i)
    {
        process.nextTick(function()
        {
            run(i);
        });
    }
};

// add a new callback to the processor chain. 
Processor.prototype.add = function add(item)
{
    var self = this;
    this.items.push(function(next)
    {
        var _next = once(function(){
          clearTimeout(timeout);
          next();
        });

        // set a timeout so that if for some reason the item fails and doesn't call its callback,
        // we make sure that the chain doesn't break.
        var timeout = setTimeout(function()
        {
            fire(self, 'timeout')
            _next();
        }, self.timeout);
        try
        {
            item(_next);
        }
        catch(ex)
        {
            fire(self, 'error', ex);
            _next();
        }
    });
}

// stop any additional iterations from happening
Processor.prototype.stop = function stop()
{
    this.started = false;
    clearTimeout(this._timeout);
    fire(this, 'stopped');
}

// start the loop
Processor.prototype.start = function start()
{
    // if not started yet and there are items to process
    if (!this.started && this.items.length > 0)
    {
        var self = this;
        self.started = true;
        self.batch = 0;

        function run(i)
        {
            i = i || 0;
            // call the runStart event
            if (i == 0)
            {
                self.batch++;
                fire(self, 'batchStart');
            }

            // if not the end of the loop
            if (i < self.items.length)
            {
                // run the current item, pass in the next run as the next function
                self.items[i](function(){ run(++i);})
            }
            // if no more items to process then check if still running and if so then schedule the next batch
            else if (self.started)
            {
                fire(self, 'batchEnd');

                if (self.maxBatches && self.maxBatches == self.batch)
                {
                    self.stop();
                }
                else
                {
                    self._timeout = setTimeout(run, self.interval);
                }
            }
        }

        // if nextTick is true then wrap each run within a nextTick call
        if (this.nextTick)
        {
            run = nextTick(run);
        }

        // run the first batch now
        run();
        return true;
    }

    return false;
}



module.exports = Processor;
Code
Diff
  • public class Program {
      public static String digitToText(int digit) {
        final String[] nums = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
        return nums[digit];
      }
    }
    
    • const nums = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
    • function digitToText(digit) {
    • return nums[digit]
    • }
    • public class Program {
    • public static String digitToText(int digit) {
    • final String[] nums = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    • return nums[digit];
    • }
    • }

Optimized it a bit

Code
Diff
  • function sum(a,b) {
      let n = 0;
      while (n < 1000000000)
        {
          n++;
        }
      return a + b;
    }
    • function sum(a,b) {
    • return a+b; // wrong returning
    • let n = 0;
    • while (n < 1000000000)
    • {
    • n++;
    • }
    • return a + b;
    • }
Code
Diff
  • function sumNechet(a, b) {
      let sum = 0;
      for(let i = a; i <=b; i++) {
        if(нечетное(i)) sum += i;
      }
      return sum;
    }
    
    function нечетное(число) {
      return число % 2 === 1;
    }
    • function sumNechet(a, b) {
    • let sum = 0;
    • for(let i = a; i <=b; i++) {
    • if(нечетное(i)) sum += i;
    • }
    • return sum;
    • }
    • function нечетное(число) {
    • return число % 2 === 1;
    • }
Code
Diff
  • SELECT *
    FROM employees
    ORDER BY salary DESC
    LIMIT 10
    • -- Code Here
    • SELECT *
    • FROM employees
    • ORDER BY salary DESC
    • LIMIT 10
Code
Diff
  • fn add_arr(arr: &[i32]) -> i32 {
        arr.iter().sum()
    }
    • function addArr(arr){
    • if(arr.length === 0) return null
    • let final = 0
    • arr.forEach(num => {
    • final += num
    • })
    • return final
    • fn add_arr(arr: &[i32]) -> i32 {
    • arr.iter().sum()
    • }