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
Lists
Data Structures

Given two numbers, you must create a list of N items that alternates between one and the other.

Example:

If the input is "first_number"=2, "second_number"=5, "elements_on_list"=10,"range_begins_at"=0 the output should be:
[2, 5, 2, 5, 2, 5, 2, 5, 2, 5]

If the input is "first_number"=10, "second_number"=7, "elements_on_list"=23,"range_begins_at"=0 the output should be:
[10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10]

def generate_binay_list(first_number,second_number,elements_on_list,range_begins_at):
    return [first_number if x%2==0 else second_number for x in range(range_begins_at, elements_on_list)]

add two numbers

public class Kumite {
  public static int add(int x, int y) {
    return x+y;
  }
}
Closures
Basic Language Features
Fundamentals
Mathematics
Algorithms
Logic
Numbers
Data Types
  • This function takes colors as arguments in the only RGBA
  • @param {String} positiveColor
  • @param {String} negativeColor
  • @param {String} neutralColor
  • @return {Function} Which takes a percentage as an argument and returns the color depending on the percentage passed
const calculateColor = ({ positive: positiveColor, negative: negativeColor, neutral: neutralColor }) => {
  return percent => {

    const absoluteValueOfNumber = Math.sign(percent)
    const startPercent = 100
    const opacityNeutral = 0.5
    const opacityMinimal = 0.25
    const isOpacityMinimal = val => val <= opacityMinimal

    if (absoluteValueOfNumber === 1) {
      const opacity = percent / startPercent

      if (isOpacityMinimal(opacity)) {
        return assignOpacity(positiveColor, opacityMinimal)
      }

      return assignOpacity(positiveColor, opacity)
    }

    if (absoluteValueOfNumber === -1) {
      const opacity = Math.abs(percent) / startPercent

      if (isOpacityMinimal(opacity)) {
        return assignOpacity(negativeColor, opacityMinimal)
      }

      return assignOpacity(negativeColor, opacity)
    }

    if (absoluteValueOfNumber === 0) {
      return assignOpacity(neutralColor, opacityNeutral)
    }
  }
}

function assignOpacity (color, value) {
  const colorArr = color.split(',').reverse()
  const opacity = colorArr[0]
  const bracket = opacity[opacity.length - 1]
  colorArr[0] = value + bracket
  return colorArr.reverse().join()
}
Closures
Basic Language Features
Fundamentals
ES2015
Babel
Functions
Control Flow
const unknown = 'Unknown error'
const catalog = {
  en: {
    ERROR_USER_NOT_FOUND: 'Error: User not found',
    ERROR_500: 'Internal Server Error',
  },
  ru: {
    ERROR_USER_NOT_FOUND: 'Ошибка: Пользователь не найден',
  }
}

const catalogProvider = locale => error => catalog[locale][error] || unknown
#include <iostream>
#include <range/v3/view/take.hpp>
#include <range/v3/view/all.hpp>

int func(){
  std::vector<int> vec = {4, 5, 6, 10};
  auto stuff = ranges::views::all(vec)  | ranges::views::take(2);
  
  for(auto x: stuff)
    std::cout << x << std::endl;
  
  return 0;
}
const normalizeChance = (items) => items
    .reduce((acc, current, i) => {
      const last = acc [i-1];
      return [
        ...acc,
        {
          ...current,
          chance: current.chance + (last ? last.chance : 0)
        },
      ];
    }, []);

const raffel = (rng, items) => {
  const normalizedItems = normalizeChance(items);
  if(normalizedItems[normalizedItems.length-1].chance !== 1) throw new Error("Sum of chance should be equal to 1")
  return () => {
    const winningNumber = rng();
    const item = normalizedItems
      .find(({ chance }) => winningNumber <= chance)

    return {
      ...item,
      winningNumber,
    }
  }
}
Strings
Data Types

Your task is to remove every second char in a string.

Example:

removeEverySecond('hello world'); // 'hlowrd'
removeEverySecond('how you doing') // 'hwyudig'
function removeEverySecond(str) {
  return [...str].filter((_,i) => !(i%2)).join``;
}

Given a binary tree defined as below, return the height of the tree.

class Node {
    constructor(val) {
        this.data = val;
        this.left = null;
        this.right = null;
    }
}```


Example:(TBD)
function treeHeight(node)
 {
     if (node == null)
         return 0;
     else
     {
         /* compute the height of each subtree */
         var lheight = treeHeight(node.left);
         var rheight = treeHeight(node.right);
 
         /* use the larger one */
         if (lheight > rheight)
         {
             return(lheight + 1);
         }
         else {
           return(rheight + 1);
         }
     }
 }
Fundamentals
Numbers
Data Types
Logic

Write a method that returns a greater number.

Perfect task for begginers!
Welcome to CodeWars!
public class Math
{
  public int Max(int a, int b)
  {
    return (a > b) ? a : b;
  }
}
# You can test with testthat (http://r-pkgs.had.co.nz/tests.html#test-structure)
# TODO: replace with your own tests (TDD), these are just here to demonstrate usage.

test_that("example", {
  expect_equal(actual, expected)
})