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

It's binarySearch implementation on JS. This returns the index number that contains the value. If the value is not in the array, it will return -1

function binarySearch(arr, el) {
  let left = -1;
  let right = arr.length;
  
  while (right - left > 1) {
    const mid = Math.floor((left + right) / 2);  
    if (arr[mid] === el) {
      return mid;
    }
    if (arr[mid] > el) {
      right = mid;
    } else {
      left = mid;
    }
  }
  return -1;
}
Strings
Data Types
Fundamentals
Basic Language Features
Algorithms
Logic

Hello Everyone!
In this Kata/Kumite we will work with strings!!

You have to find all chars indexes passed by parameter in a string
and replace them with the index parameter with pad left '0'.


EXAMPLE 1:

sValueReplacer("9182 7391238 91$$$$", 3, '$');

RESULT 1:

9182 7391238 910003


EXAMPLE 2:

sValueReplacer("The counter is ---", 11, '-');

RESULT 2:

"The counter is 011"


using System;
using System.Linq;
using System.Collections.Generic;

public class Test{
  static void Main(){
    Console.WriteLine(Replacer.sValueReplacer("0000##81#059671####=1811", 3, '#'));
  }
}

public class Replacer{

  public static string sValueReplacer(string source, int index, char char_to_replace)
  {
    string res = source;

    try
    {
      if (!string.IsNullOrEmpty(char_to_replace.ToString()))
      {
        if (res.Contains(char_to_replace.ToString()))
        {
           // Get ALL Indexes position of character
           var Indexes = GetIndexes(res, char_to_replace.ToString());

           int max = GetMaxValue(Indexes.Count);

           while (index >= max) 
           { 
            index -= max; 
           }

           var new_value = index.ToString().PadLeft(Indexes.Count, '0');

           for (int i = 0; i < Indexes.Count; i++)
           {
            res = res.Remove(Indexes[i], 1).Insert(Indexes[i], new_value[i].ToString());
           }
        }
      }
     }
     catch (Exception)
     {
      res = source;
     }

     return res;
  }
  
  private static List<int> GetIndexes(string mainString, string toFind)
  {
    var Indexes = new List<int>();

    for (int i = mainString.IndexOf(toFind); i > -1; i = mainString.IndexOf(toFind, i + 1))
    {
      // for loop end when i=-1 (line.counter not found)
      Indexes.Add(i);
    }

    return Indexes;
   }

   private static int GetMaxValue(int numIndexes)
   {
      int max = 0;

      for (int i = 0; i < numIndexes; i++)
      {
        if (i == 0)
          max = 9;
        else
          max = max * 10 + 9;
      }

      return max;
    }
}
# 90 degrees clockwise matrix rotate
def rotate(m):
    return list(zip(*m))[::-1]
Encoding
Algorithms
Logic

Create a function, that takes string as its only argument and yields rot13-encoded string. Only standard latin letters must be affected, avoid touching other characters and whitespaces.

defmodule Rot13 do
  def rotate({k, v}) do
    cond do
      v in ?A..?M ->
        k + 13

      v in ?N..?Z ->
        k - 13

      true ->
        k
    end
  end
  
  def encode(str) do
    List.zip([
      str
      |> String.to_charlist(),
      str
      |> String.upcase()
      |> String.to_charlist()
    ])
    |> Enum.map(&rotate/1)
    |> List.to_string()
  end
end

The function take a number and checks if it is in the Fibonnacci Sequence. If it is return "yes", else return "no".

Fibonnacci sequence explained:
starts with 0 and 1. It adds the two previous numbers to get the next one, then continues the pattern.

Some of the beginning sequence: 0,1,1,2,3,5,8,13,21...

function isSquare(x) { 

  // code goes here  
  let sq = parseInt(Math.sqrt(x));
  return check = (sq * sq == x)
}

function FibonacciChecker(num){
  return (isSquare(5 * num * num + 4) || isSquare(5 * num * num -4)) ? "yes" : "no";
  
}

In this kata you are restructuring given object with agregated properties by underscore into nested object

Sample transformation :

const before = {
a_b_c : 'value'
}

restructured into:

const after = {
a : {
b: {
c: 'value'
}
}
}

export function transform(obj: any) {
    const _RegEx = new RegExp(/_/);
    const underscoredProp = Object.keys(obj).find(key =>
        _RegEx.test(key)) || '';
    const value = obj[underscoredProp];
    const propertList = underscoredProp.split('_').reverse();
    let toAdd = {};

    propertList.map((prop,index) => {
       toAdd = index==0 ?{[prop]:value}  : {[prop]:toAdd}
        
    })

    return toAdd;
}
const {execSync} = require('child_process');
execSync(`echo '{"foo": "bar"}' >file.json`);
console.log(require('./file.json'));
execSync(`echo '{"baz": "qux"}' >file.json`);
console.log(require('./file.json')); // cached

ALLOW FRIENDS TO ADD ME THROUGH KUMITE

#include<iostream>

std::string dfescribe(std::string){
  
};
/*
Description:
"7777...8?!??!", exclaimed Bob, "I missed it again! Argh!" Every time there's an interesting number coming up, he notices and then promptly forgets. Who doesn't like catching those one-off interesting mileage numbers?
Let's make it so Bob never misses another interesting number. We've hacked into his car's computer, and we have a box hooked up that reads mileage numbers. We've got a box glued to his dash that lights up yellow or green depending on whether it receives a 1 or a 2 (respectively).
It's up to you, intrepid warrior, to glue the parts together. Write the function that parses the mileage number input, and returns a 2 if the number is "interesting" (see below), a 1 if an interesting number occurs within the next two miles, or a 0 if the number is not interesting.
Note: In Haskell, we use No, Almost and Yes instead of 0, 1 and 2.
"Interesting" Numbers
Interesting numbers are 3-or-more digit numbers that meet one or more of the following criteria:
Any digit followed by all zeros: 100, 90000
Every digit is the same number: 1111
The digits are sequential, incementing†: 1234
The digits are sequential, decrementing‡: 4321
The digits are a palindrome: 1221 or 73837
The digits match one of the values in the awesomePhrases array
† For incrementing sequences, 0 should come after 9, and not before 1, as in 7890.
‡ For decrementing sequences, 0 should come after 1, and not before 9, as in 3210.
So, you should expect these inputs and outputs:
// "boring" numbers
isInteresting(3, [1337, 256]);    // 0
isInteresting(3236, [1337, 256]); // 0
// progress as we near an "interesting" number
isInteresting(11207, []); // 0
isInteresting(11208, []); // 0
isInteresting(11209, []); // 1
isInteresting(11210, []); // 1
isInteresting(11211, []); // 2
// nearing a provided "awesome phrase"
isInteresting(1335, [1337, 256]); // 1
isInteresting(1336, [1337, 256]); // 1
isInteresting(1337, [1337, 256]); // 2
Error Checking
A number is only interesting if it is greater than 99!
Input will always be an integer greater than 0, and less than 1,000,000,000.
The awesomePhrases array will always be provided, and will always be an array, but may be empty. (Not everyone thinks numbers spell funny words...)
You should only ever output 0, 1, or 2.
*/
const chars = n => n.toString().split("");
const match = s => n => new RegExp(n).test(s);

const tests = [
  match("1234567890"), // incremental
  match("9876543210"), // decremental
  n => /^\d[0]+$/.test(n), // all zeroes
  n =>
    n ==
    chars(n)
      .reverse()
      .join(""), // palindrome
  n => [...new Set(chars(n))].length === 1 // repeated
];

const test = (n, xs) =>
  n > 99 && (xs.indexOf(n) > -1 || tests.map(t => t(n)).some(x => !!x));

const isInteresting = (n, xs) =>
  test(n, xs) ? 2 : +(test(n + 1, xs) || test(n + 2, xs));
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
  }
}