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
Regular Expressions
Declarative Programming
Advanced Language Features
Programming Paradigms
Fundamentals
Strings

With the power of regex it becomes easy to tell if your string has even length!

class StringParity {
  public static boolean isEvenLength(String str) {
    return str.replaceAll("(?s)..", "").isEmpty(); // (?s) enables DOTALL
  }
}

In this simple exercise, you will build a program that takes a value, integer , and returns a list of its multiples up to another value, limit . If limit is a multiple of integer, it should be included as well. There will only ever be positive integers passed into the function, not consisting of 0. The limit will always be higher than the base.

For example, if the parameters passed are (2, 6), the function should return [2, 4, 6] as 2, 4, and 6 are the multiples of 2 up to 6.

If you can, try writing it in only one line of code.

def find_multiples(b, l):
    a=[]
    for i in range(b,l+1,b):
        
        a.append(i)
    return a
...
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``;
}