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.
Create a function that does four basic mathematical operations.
The function should take three arguments - operation(string/char), value1(number), value2(number).
The function should return result of numbers after applying the chosen operation.
example:
basicOp('+', 4, 8) // Output: 12
basicOp('-', 14, 18) // Output: -4
basicOp('*', 5, 4) // Output: 20
basicOp('/', 49, 7) // Output: 7
Suppose we're adding 1 and -1. That would return 0, which would be a valid result for this operation. But trying to use an invalid operation would also return 0, so now there's no concrete way of knowing if the function executed correctly.
function basicOp(operation, value1, value2) {
switch (operation) {
case '+':
return value1 + value2;
case '-':
return value1 - value2;
case '*':
return value1 * value2;
case '/':
return value1 / value2;
default:
return 0;
//Suppose we're adding 1 and -1.
}
}
// TODO: Add your tests here
// Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework.
// [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework)
// are still available for now.
//
// For new tests, using [Chai](https://chaijs.com/) is recommended.
// You can use it by requiring:
// const assert = require("chai").assert;
// If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted.
describe("Solution", function() {
it("should test for something", function() {
// Test.assertEquals(1 + 1, 2);
// assert.strictEqual(1 + 1, 2);
});
});
Your task:
Instead of writing out the same code over and over, let’s make the computer loop through our array for us. We can do this with for loops.
Some help for beginners:
Since this syntax is a little complicated, let’s break it into 4 parts:
Within the for loop’s parentheses, the start condition is var i = 0, which means the loop will start counting at 0.
The stop condition is i < animals.length, which means the loop will run as long as i is less than the length of the animals array. When i is greater than the length of the animals array, the loop will stop looping.
The iterator is i++. This means that each loop, i will have 1 added to it.
And finally, the code block is inside the { ... }. The block will run each loop, until the loop stops.
Tip of the day:
The secret to loops is that i, the variable we created inside the for loop’s parentheses, is always equal to a number. To be more clear, the first loop, i will equal 0, the second loop, i will equal 1, and the third loop, i will equal 2.
This makes it possible to write animals[0], animals[1], animals[2] programmatically instead of by hand. We can write a for loop, and replace the hard coded number with the variable i, like this: animals[i].
var animals = ["Grizzly Bear", "Sloth", "Sea Lion"];
//your code here
}
// TODO: Add your tests here
// Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework.
// [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework)
// are still available for now.
//
// For new tests, using [Chai](https://chaijs.com/) is recommended.
// You can use it by requiring:
// const assert = require("chai").assert;
// If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted.
describe("Solution", function() {
it("should test for something", function() {
// Test.assertEquals(1 + 1, 2);
// assert.strictEqual(1 + 1, 2);
});
});
Write a function that takes an integer as input, and returns boolean divisibility by 3 for input argument. You can't use /
as operator
Example: The number 3
is divisible by three without leaving a remainder, so the function should return true
in this case
function dividedByThree(int $number): bool
{
$i = 3;
do {
if (abs($number) === $i) {
return true;
}
$i += 3;
} while (abs($number) >= $i);
return false;
}
class MyTestCases extends TestCase
{
public function testDividedByThree() {
$this->assertTrue(dividedByThree(3));
$this->assertTrue(dividedByThree(12));
$this->assertFalse(dividedByThree(13));
$this->assertFalse(dividedByThree(0));
$this->assertTrue(dividedByThree(-12));
}
}
You will have an input and a factor.
Multiply the String by the factor.
For example: "hi",2 -> "hihi"
public class Kata{
public static String multiply(String input,int times){
String save = input;
for (int i = 1; i < times; i++) {
System.out.println(input);
input += save;
}
if(times == 0){
input = "";
}
return input;
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
// TODO: Replace examples and use TDD development by writing your own tests
public class SolutionTest {
@Test
public void testSomething() {
assertEquals("lsadfkjlsadfkjlsadfkj",Kata.multiply("lsadfkj",3));
assertEquals("hellohellohellohello",Kata.multiply("hello",4));
assertEquals("",Kata.multiply("hu",0));
}
}
FilteredText array needs to check all its objects and their properties. If the property is different then it becames "Mixed data".
The Output should look like this:
filteredText = [
{
innerHTML: 'Hello World',
fontSize: 'Mixed data',
fontWeight: '700',
},
{
innerHTML: 'Hello World',
fontSize: 'Mixed data',
fontWeight: '400',
},
{
innerHTML: 'Hello World',
fontSize: 'Mixed data',
fontWeight: '400',
},
]
let baseData = [
{
input_text1: "{'innerHTML': 'Hello World', 'fontSize': '5', 'fontWeight': '700'}",
input_text2: "{'innerHTML': 'Hello World', 'fontSize': '5', 'fontWeight': '400'}",
input_text3: "{'innerHTML': 'Hello World', 'fontSize': '5', 'fontWeight': '400'}",
input_shape1: "{x: 7, y, 150, width: 50, height: 50}",
input_shape2: "{x: 150, y, 80, width: 50, height: 50}",
input_shape3: "{x: 67, y, 150, width: 50, height: 50}",
},
{
input_text1: "{'innerHTML': 'Hello World', 'fontSize': '10', 'fontWeight': '700'}",
input_text2: "{'innerHTML': 'Hello World', 'fontSize': '5', 'fontWeight': '400'}",
input_text3: "{'innerHTML': 'Hello World', 'fontSize': '5', 'fontWeight': '400'}",
input_shape1: "{x: 50, y, 150, width: 50, height: 50}",
input_shape2: "{x: 150, y, 80, width: 50, height: 50}",
input_shape3: "{x: 30, y, 150, width: 50, height: 50}",
},
{
input_text1: "{'innerHTML': 'Hello World', 'fontSize': '5', 'fontWeight': '700'}",
input_text2: "{'innerHTML': 'Hello World', 'fontSize': '5', 'fontWeight': '400'}",
input_text3: "{'innerHTML': 'Hello World', 'fontSize': '5', 'fontWeight': '400'}",
input_shape1: "{x: 7, y, 150, width: 50, height: 50}",
input_shape2: "{x: 150, y, 50, width: 50, height: 50}",
input_shape3: "{x: 67, y, 150, width: 50, height: 50}",
},
]
let filteredText = baseData.map(el => {
return Object.entries(el).filter(key => key[0].includes('text'))
});
def greatest_common_divisor(*args):
def gcd(a, b):
if a == b: return a
elif a > b:
return (gcd(b, a % b) if a % b != 0 else b)
else:
return gcd(b, a)
res = gcd(args[0], args[1])
if len(args) > 2:
for i in range(2, len(args)):
res = gcd(res, args[i])
return res
test.assert_equals(greatest_common_divisor(6, 4), 2)
test.assert_equals(greatest_common_divisor(2, 4, 8), 2)
test.assert_equals(greatest_common_divisor(2, 3, 5, 7, 11), 1)
test.assert_equals(greatest_common_divisor(3, 9, 3, 9), 3)
A Class that helps with computing Fibonacci numbers, by treating them as linkedlist entries.
Calling FibonacciSequence next() outputs a biginteger for the current fibonacci value of the sequence's instance.
The sequence starts at 1.
import java.math.BigInteger;
public class FibonacciSequence {
private BigInteger first;
private BigInteger second;
public FibonacciSequence() {
second = BigInteger.ONE;
first = BigInteger.ZERO;
}
public BigInteger next() {
BigInteger returnVal = second;
updateValues();
return returnVal;
}
private void updateValues() {
BigInteger t = second;
second = first.add(t);
first = t;
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
import java.math.BigInteger;
// TODO: Replace examples and use TDD development by writing your own tests
public class SolutionTest {
@Test
public void testSomething() {
assertEquals("1", getFibonacci(1).toString());
assertEquals("1", getFibonacci(2).toString());
assertEquals("2", getFibonacci(3).toString());
assertEquals("3", getFibonacci(4).toString());
assertEquals("5", getFibonacci(5).toString());
assertEquals("8", getFibonacci(6).toString());
assertEquals("13", getFibonacci(7).toString());
assertEquals("21", getFibonacci(8).toString());
assertEquals("34", getFibonacci(9).toString());
assertEquals("55", getFibonacci(10).toString());
assertEquals("89", getFibonacci(11).toString());
assertEquals("144", getFibonacci(12).toString());
assertEquals("233", getFibonacci(13).toString());
}
private BigInteger getFibonacci(long iterations){
FibonacciSequence seq = new FibonacciSequence();
BigInteger result = BigInteger.ZERO;
for(long i = 0; i < iterations; i++){
result = seq.next();
}
return result;
}
}
wenn der übergebenen string mit a anfängt, gebe true zurück
public class test{
public static Boolean anfanga(String s){
if(s.startsWith("a")){
return true;
} else {
return false;
}
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
// TODO: Replace examples and use TDD development by writing your own tests
public class SolutionTest {
@Test
public void testSomething() {
assertEquals(true, test.anfanga("arbeit"));
assertEquals(false, test.anfanga("text"));
}
}
You type a string of a list of numbers, and this method returns the highest int and the lowest int in the string.
public class ns {
public static String highAndLow(String numbers) {
String[] integerStrings = numbers.split(" ");
int[] integers = new int[integerStrings.length];
for (int i = 0; i < integers.length; i++){
integers[i] = Integer.parseInt(integerStrings[i]);
}
int maxValue = integers[0];
for(int y=1;y < integers.length;y++){
if(integers[y] > maxValue){
maxValue = integers[y];
}
}
int minValue = integers[0];
for(int q=1;q<integers.length;q++){
if(integers[q] < minValue){
minValue = integers[q];
}
}
String s = Integer.toString(maxValue);
String m = Integer.toString(minValue);
String r = s + " " + m;
return r;
}
public static void main(String args[]) {
System.out.println(highAndLow("13 48 19 20 24 12"));
}
}