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.

let stringToHTML = (el = 'div', attr = [], template = '') => 
  `<${el} ${attr.join(' ')}>${template}</${el}>`,
  
  element = 'a',
  content = "https://www.codewars.com"
  attributes = [`href='${content}'`, "class='link'"];
  
stringToHTML(element, attributes, content);

// => "<a href='https://www.codewars.com' class='link'>https://www.codewars.com</a>"

Passed and failing tests with imports etc

Code
Diff
  • class Person {
      String firstName;
      String lastName;
      
      Person(this.firstName,this.lastName);
      
      String get fullName => '$firstName $lastName';
    }
  • 1
    doubler(n) => n*2;
    
    1+
    class Person {
    
    2+
      String firstName;
    
    3+
      String lastName;
    
    4+
      
    
    5+
      Person(this.firstName,this.lastName);
    
    6+
      
    
    7+
      String get fullName => '$firstName $lastName';
    
    8+
    }
    

For some reason I keep using this function as a test in all the runner changes

fn doubler(n:i32) -> i32 {
  n * 2
}
Code
Diff
  • module InfiniteSeq where
    
    import Data.List
    
    ones = repeat 1
    nats = [0..]
    
    merge = concat . transpose
    merge2 x y = merge [x, y]
    
    ints = 0: merge2 [1..] [(-1),(-2)..]
    
    fibs = 1 : scanl (+) 1 fibs
  • 66
    nats = [0..]
    
    77
    88
    merge = concat . transpose
    
    99
    merge2 x y = merge [x, y]
    
    1010
    1111
    ints = 0: merge2 [1..] [(-1),(-2)..]
    
    12+
    13+
    fibs = 1 : scanl (+) 1 fibs
    

Looks like C++ and C# return their tests in alphabetical order.

int a = 1;

There seems to be an error with looking at the top of a stack, but it doesn't throw. It just kills execution. What's going on here?

#include <stack>

bool method() 
{
  std::stack<int> my_stack;
  //my_stack.push(1);
  try {
    if(my_stack.top()) 
    {
    }
  }
  catch(...) {
    std::cout << "An Exception Occurred" << std::endl;
  }
  return true;
}

(Functional version with no loops)

Code
Diff
  • Number.prototype.times = function(f) { 
      const n = this.valueOf()
      const g = (_, i) => f(i)
      return [...Array(n)].map(g) 
    }
    
  • 1
    Number.prototype.times = function (f) {
    
    2
      for (let i = 0; i < this; i++) f(i);
    
    1+
    Number.prototype.times = function(f) { 
    
    2+
      const n = this.valueOf()
    
    3+
      const g = (_, i) => f(i)
    
    4+
      return [...Array(n)].map(g) 
    
    33
    }
    

Recent Moves:

Code
Diff
  • var merge = (array1, array2, callbackFN) => callbackFN(array1,array2);
    
    callbackFN = (a,b) => Array.isArray(a) && Array.isArray(b) && a.length === b.length ?
      a.map((c, i) => c + b[i])
      : 'both inputs must be Array and same size of elements';  
    
    var x = merge([1, 3, 4], [5, 6, 7, 8], callbackFN);
    console.log(x);   //'both inputs must be Array and same size of elements'
    
    x = merge([1, 2, 3, 4], [5, 6, 7, 8], callbackFN);
    console.log(x);   //[6, 8, 10, 12].
  • 1
    var merge = function(array1, array2, callbackFN){ 
    
    2
     return callbackFN(array1,array2);
    
    3
    }
    
    1+
    var merge = (array1, array2, callbackFN) => callbackFN(array1,array2);
    
    44
    5
    function callbackFN(a,b) {
    
    6
      if(Array.isArray(a) && Array.isArray(b) && (a.length === b.length)){
    
    7
        return a.map(function(c,i){ return c + b[i]; });
    
    8
      } else {
    
    9
        return 'both inputs must be Array and same size of elements';
    
    10
      }
    
    11
      
    
    12
    }
    
    3+
    callbackFN = (a,b) => Array.isArray(a) && Array.isArray(b) && a.length === b.length ?
    
    4+
      a.map((c, i) => c + b[i])
    
    5+
      : 'both inputs must be Array and same size of elements';  
    
    1313
    1414
    var x = merge([1, 3, 4], [5, 6, 7, 8], callbackFN);
    
    15
    console.log(x);   //x should now equal [6, 8, 10, 12].
    
    8+
    console.log(x);   //'both inputs must be Array and same size of elements'
    
    9+
    10+
    x = merge([1, 2, 3, 4], [5, 6, 7, 8], callbackFN);
    
    11+
    console.log(x);   //[6, 8, 10, 12].
    
Code
Diff
  • let greetLanguage = (greeting = "Hello", language = "Javascript") => `${greeting}, ${language}!`;
  • 1
    function greetLanguage(greeting = "Hello", language = "Javascript") {
    
    2
      var result = `${greeting}, ${language}!`;
    
    3
      console.log(result);
    
    4
      return result;
    
    5
    }
    
    1+
    let greetLanguage = (greeting = "Hello", language = "Javascript") => `${greeting}, ${language}!`;