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.
function calcGPA(string) {
string = string.split(' ');
let total = 0
string.forEach(x => {
if (x >= 90) return total += 4
if (x >= 80) return total += 3
if (x >= 70) return total += 2
if (x >= 60) return total += 1
})
return total / string.length
}
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
// chai.config.truncateThreshold = 0;
describe("Solution", function() {
it("Test", function() {
assert.strictEqual(calcGPA("100 95 92 99"), 4.0);
assert.strictEqual(calcGPA("80 44 31 91"), 1.75);
assert.strictEqual(calcGPA("72 9 69 72"), 1.25);
assert.strictEqual(calcGPA("41 32 71 30"), 0.5);
});
});
New user, sorry if I'll only use the title and description
This is around 6 kyu i think
Inputs are always array
function returnLastNonRepNum(arr) {
for (let i = arr.length ; i > 0; i-- ) {
if (typeof(arr[i]) === 'number' && arr.indexOf(arr[i]) === arr.lastIndexOf(arr[i])) {
return arr[i]
}
}
}
let arr = [ 1, 'a', 6, 'c', 9, 9, 66, 's', 66, '6'];
console.log(returnLastNonRepNum(arr))
// should output 6
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
describe("Solution", function() {
it("should test for something", function() {
// Test.assertEquals(1 + 1, 2);
// assert.strictEqual(1 + 1, 2);
});
});
Simulating the UEFA Champions League Draw. Code is long because of the team data.
/*2021.12.13. Draw of the UEFA Champions League quarter-finals.
This was a joke with a bad software. Decided to code a better one.
There are 16 teams, 8 group-winners and 8 runners-up.
A runner-up team is drawed first from the 8. It is paired with a gruop-winner.
There are 2 rules:
it can not go from the same group
it can not have the same nationality.
After the pairing, the paired teams are taken out of the list before the next draw.
*/
/*database: 2 arrays of objects*/
const groupWinners = [
{
name: "Manchester City",
group: "A",
nationality: "English"
},
{
name: "Liverpool",
group: "B",
nationality: "English"
},
{
name: "Ajax Amsterdam",
group: "C",
nationality: "Dutch"
},
{
name: "Real Madrid",
group: "D",
nationality: "Spanish"
},
{
name: "Bayern Munich",
group: "E",
nationality: "German"
},
{
name: "Manchester United",
group: "F",
nationality: "English"
},
{
name: "Lille",
group: "G",
nationality: "French"
},
{
name: "Juventus",
group: "H",
nationality: "Italian"
}
];
const runnersUp = [
{
name: "Paris Saint-Germain",
group: "A",
nationality: "French"
},
{
name: "Atletico Madrid",
group: "B",
nationality: "Spanish"
},
{
name: "Sporting CP",
group: "C",
nationality: "Portuguese"
},
{
name: "Internazionale",
group: "D",
nationality: "Italian"
},
{
name: "Benfica",
group: "E",
nationality: "Portuguese"
},
{
name: "Villarreal",
group: "F",
nationality: "Spanish"
},
{
name: "FC Salzburg",
group: "G",
nationality: "Austrian"
},
{
name: "Chelsea",
group: "H",
nationality: "English"
}
];
console.log("\n");
console.log("WELCOME IN THE DRAW OF THE UEFA CHAMPIONS LEAGUE QUARTER-FINALS!");
console.log("\n");
/*arrays containing teams which can be still drawed and an array for the pairings*/
let groupWinnersToDraw = [...groupWinners];
let runnersUpToDraw = [...runnersUp];
let pairings = [];
/*while there are teams to draw */
while (runnersUpToDraw.length > 0) {
/*choose a random team from runnersUpToDraw */
let index = Math.floor(Math.random()*(runnersUpToDraw.length));
let teamToFace = runnersUpToDraw[index];
/*updating the runnersUpToDraw array*/
runnersUpToDraw = runnersUpToDraw.slice(0, index).concat(runnersUpToDraw.slice(index+1, runnersUpToDraw.length));
console.log("Team to face:", teamToFace.name, teamToFace.group, teamToFace.nationality);
console.log("\n");
/*selecting the potential opponents */
let potentialOpponents = groupWinnersToDraw.filter(team =>
(team.group != teamToFace.group && team.nationality != teamToFace.nationality)
);
console.log("Potential opponents:")
potentialOpponents.forEach(team => console.log(team.name, team.group, team.nationality));
console.log("\n");
/*choose a random team from potentialOpponents */
let anotherIndex = Math.floor(Math.random()*(potentialOpponents.length));
let opponent = potentialOpponents[anotherIndex];
console.log("The opponent is:", opponent.name, opponent.group, opponent.nationality);
console.log("\n");
/*updating the groupWinnersToDraw array*/
let yetAnotherIndex = 0;
for (let i = 0; i < groupWinnersToDraw.length; i++) {
if (groupWinnersToDraw[i].name == opponent.name) {
yetAnotherIndex = i;
}
}
groupWinnersToDraw = groupWinnersToDraw.slice(0, yetAnotherIndex).concat(groupWinnersToDraw.slice(yetAnotherIndex+1, groupWinnersToDraw.length));
console.log("Remaining group-winners:")
groupWinnersToDraw.forEach(team => console.log(team.name));
console.log("\n");
/*save the pairings */
let drawing = [];
drawing.push(teamToFace);
drawing.push(opponent);
pairings.push(drawing);
}
/*log the draw */
console.log("THE QUARTER-FINALS: ");
console.log("\n");
pairings.forEach(pair => {
console.log(pair[0].name, pair[0].group, pair[0].nationality, " vs ",
pair[1].name, pair[1].group, pair[1].nationality );
});
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
// chai.config.truncateThreshold = 0;
// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
// Uncomment the following to use the old assertions:
// const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("should test for something", function() {
// Test.assertEquals(1 + 1, 2);
// assert.strictEqual(1 + 1, 2);
});
});
The Tower of Hanoi is a mathematical puzzle. It consists of three poles and a number of disks of different sizes which can slide onto any poles. The puzzle starts with the disk in a neat stack in ascending order of size in one pole, the smallest at the top thus making a conical shape. The objective of the puzzle is to move all the disks from one pole (say ‘source pole’) to another pole (say ‘destination pole’) with the help of the third pole (say auxiliary pole).
The puzzle has the following two rules:
1. You can’t place a larger disk onto a smaller disk
2. Only one disk can be moved at a time
using System.Collections.Generic;
using System.Diagnostics;
public class TowerOfHanoi
{
public static int Tower(int numOfDisks)
{
return 0;
}
private static int Tower(int n, string source, string aux, string dest, Dictionary<int, int> cache)
{
return 0;
}
}
using NUnit.Framework;
using System;
[TestFixture]
public class TowerOfHanoi_Tests
{
[Test]
public void Hanoi_Test()
{
var moves = TowerOfHanoi.Tower(1);
Assert.AreEqual(1, moves);
moves = TowerOfHanoi.Tower(2);
Assert.AreEqual(3, moves);
moves = TowerOfHanoi.Tower(3);
Assert.AreEqual(7, moves);
moves = TowerOfHanoi.Tower(4);
Assert.AreEqual(15, moves);
moves = TowerOfHanoi.Tower(5);
Assert.AreEqual(31, moves);
moves = TowerOfHanoi.Tower(6);
Assert.AreEqual(63, moves);
moves = TowerOfHanoi.Tower(7);
Assert.AreEqual(127, moves);
}
}
Your goal is simple: To find the one character that doesn't fit in to the string.
Example:
aaaaabaaaaa
should return "b"
No trick questions! Take it at face value.
package oddoneout
fun oddOneOut(s: String): String {
var odd = 0
var same = 0
var keepTrack = s[0]
var sameTracker = ""
var oddTracker = ""
for (i in s.indices) {
if (s[i] == keepTrack) {
same += 1
sameTracker += s[i]
} else {
odd += 1
oddTracker += s[i]
}
}
if (odd < 2) {
return oddTracker
} else {
return sameTracker
}
}
package oddoneout
import kotlin.test.assertEquals
import org.junit.Test
class TestExample {
@Test
fun tests() {
assertEquals("b", oddOneOut("aaaaabaaaaa"))
assertEquals("a", oddOneOut("llllllal"))
assertEquals("c", oddOneOut("cssssssss"))
}
}
You need to somehow turn RegExp into an array of strings, for example:
/fo?x([ea]s)?|do?gs?/
it should turn out something like this:
["fox", "fx", "foxes", "foxas", "dog", "dogs", "dg", "dgs"]
If \d
occurs in RexExp, it must generate an array from 0
to 9
if \w
then generates an array from a
to z
if \n
or \t
then ignores
and if there is a +
somewhere, then the function should return Infinity
function regexpToStringArray(regexp) {
}
const chai = require("chai");
const assert = chai.assert;
const Test = require("@codewars/test-compat");
describe("regexpToStringArray", function() {
it("Basic tests", function() {
Test.assertEquals(regexpToStringArray(/fo?x|do?g/), ["fox", "fx", "dog", "dg"]);
Test.assertEquals(regexpToStringArray(/f[oa]?x|d[oa]?g/), ["fox", "fax", "fx", "dog", "dag", "dg"]);
Test.assertEquals(regexpToStringArray(/[0-9]/), ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]);
Test.assertEquals(regexpToStringArray(/[0-9]{1,2}/), [
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'10', '11', '12', '13', '14', '15', '16', '17', '18', '19',
'20', '21', '22', '23', '24', '25', '26', '27', '28', '29',
'30', '31', '32', '33', '34', '35', '36', '37', '38', '39',
'40', '41', '42', '43', '44', '45', '46', '47', '48', '49',
'50', '51', '52', '53', '54', '55', '56', '57', '58', '59',
'60', '61', '62', '63', '64', '65', '66', '67', '68', '69',
'70', '71', '72', '73', '74', '75', '76', '77', '78', '79',
'80', '81', '82', '83', '84', '85', '86', '87', '88', '89',
'90', '91', '92', '93', '94', '95', '96', '97', '98', '99'
]);
Test.assertEquals(regexpToStringArray(/a[a-c]a/), ["aaa", "aba", "aca"]);
Test.assertEquals(regexpToStringArray(/a[a-c]{1,2}a/), [
"aaa", "aba", "aca",
"aaaa", "aaba", "aaca",
"abaa", "abba", "abca",
"acaa", "acba", "acca",
]);
Test.assertEquals(regexpToStringArray(/[0-9]+/), Infinity);
Test.assertEquals(regexpToStringArray(/[a-b]+/), Infinity);
});
});
In this kata there will be two inputs.Your task is to determine whether relative numbers are or are not, if are relative numbers then return relative and if not non relative.
Relative numbers - integers that have no common divisors other than 1 and itself.
Example: relativeNumbers(8, 9):
The number 8 has 2,4 divisors;
The number 9 has 3 divisor;
Due to the fact that the numbers 8 and 9 do not have common divisors, they are relative numbers
function relativeNumbers(a, b) {
let arrOne = [];
let arrTwo = [];
for (let i = 2; i < 10; i++) {
if (a % i === 0 && a !== i) {
arrOne.push(i);
}
if(b % i === 0 && b !== i){
arrTwo.push(i)
}
}
for(let i = 0; i < arrOne.length; i++){
for(let j = 0; j < arrTwo.length; j++){
if(arrOne[i] === arrTwo[j]){
return "non relative"
}else return "relative"
}
}
}
const chai = require("chai");
const assert = chai.assert;
chai.config.truncateThreshold = 0;
describe("relativeNumbers",()=>{
it("example tests", ()=>{
assert.deepEqual( relativeNumbers(8,9), "relative" );
});
});
Your job is to write a function which increments a string, to create a new string.
If the string already ends with a number, the number should be incremented by 1.
If the string does not end with a number. the number 1 should be appended to the new string.
Examples:
foo -> foo1
foobar23 -> foobar24
foo0042 -> foo0043
foo9 -> foo10
foo099 -> foo100
Attention: If the number has leading zeros the amount of digits should be considered.
function incrementString (strng) {
// return incrementedString
}
describe("Tests", () => {
it("test", () => {
Test.assertEquals(incrementString("foobar000"), "foobar001");
Test.assertEquals(incrementString("foo"), "foo1");
Test.assertEquals(incrementString("foobar001"), "foobar002");
Test.assertEquals(incrementString("foobar99"), "foobar100");
Test.assertEquals(incrementString("foobar099"), "foobar100");
Test.assertEquals(incrementString(""), "1");
});
});
bruh
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
// chai.config.truncateThreshold = 0;
// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
// Uncomment the following to use the old assertions:
// const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("should test for something", function() {
// Test.assertEquals(1 + 1, 2);
// assert.strictEqual(1 + 1, 2);
});
});
The function takes three parameters a, b, c. Using these parameters - find the discriminant.
The function should return an array of solutions of the form [solution1, solution2].
discriminant > 0 ? return [solution1, solution2];
discriminant = 0 ? return [solution1];
discriminant < 0 ? return ['no solutions'];
Ex: x^2−3x+2
result: [2, 1]
Note: solution1 should be greater than solution2 :)
const discriminant = (a, b, c) => {
let result = [];
let D = b*b - 4*a*c;
D < 0 ? result.push('no solutions') : result.push((b*(-1) + Math.sqrt(D)) / (2*a));
D > 0 ? result.push((b*(-1) - Math.sqrt(D)) / (2*a)) : 'xD';
return result;
}
const chai = require("chai");
const assert = chai.assert;
describe("Solution", function() {
it("ax^2 + bx + c", function() {
assert.deepEqual(discriminant(3,-18,27), [3]);
assert.deepEqual(discriminant(3,0,0), [0]);
assert.deepEqual(discriminant(1,-6,9), [3]);
assert.deepEqual(discriminant(1,-5,4), [4, 1]);
assert.deepEqual(discriminant(1,2,34), ['no solutions']);
});
});