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 wordCount(str) { // error on no matches. // also, are there any other characters besides \w and - that shouldn't break words? return str.match(/[\w-]+/g).length; }
- function wordCount(str) {
return str.split(/\s/g).filter(x => x.length > 0).length;- // error on no matches.
- // also, are there any other characters besides \w and - that shouldn't break words?
- return str.match(/[\w-]+/g).length;
- }
// TODO: Replace examples and use TDD development by writing your own tests // These are some CW specific test methods available: // Test.expect(boolean, [optional] message) // Test.assertEquals(actual, expected, [optional] message) // Test.assertSimilar(actual, expected, [optional] message) // Test.assertNotEquals(actual, expected, [optional] message) // NodeJS assert is also automatically required for you. // assert(true) // assert.strictEqual({a: 1}, {a: 1}) // assert.deepEqual({a: [{b: 1}]}, {a: [{b: 1}]}) // You can also use Chai (http://chaijs.com/) by requiring it yourself // var expect = require("chai").expect; // var assert = require("chai").assert; // require("chai").should(); Test.assertEquals(wordCount(" v"), 1); //Test.assertEquals(wordCount(" "), 1); Test.assertEquals(wordCount(" 'Twas brillig and the slithy toves; did gyre and gimble in the wabe"), 13); Test.assertEquals(wordCount("Word"), 1); Test.assertEquals(wordCount("Wo r d"), 3); Test.assertEquals(wordCount("Bob the t-rex"), 3);
- // TODO: Replace examples and use TDD development by writing your own tests
- // These are some CW specific test methods available:
- // Test.expect(boolean, [optional] message)
- // Test.assertEquals(actual, expected, [optional] message)
- // Test.assertSimilar(actual, expected, [optional] message)
- // Test.assertNotEquals(actual, expected, [optional] message)
- // NodeJS assert is also automatically required for you.
- // assert(true)
- // assert.strictEqual({a: 1}, {a: 1})
- // assert.deepEqual({a: [{b: 1}]}, {a: [{b: 1}]})
- // You can also use Chai (http://chaijs.com/) by requiring it yourself
- // var expect = require("chai").expect;
- // var assert = require("chai").assert;
- // require("chai").should();
- Test.assertEquals(wordCount(" v"), 1);
- //Test.assertEquals(wordCount(" "), 1);
- Test.assertEquals(wordCount(" 'Twas brillig and the slithy toves; did gyre and gimble in the wabe"), 13);
- Test.assertEquals(wordCount("Word"), 1);
- Test.assertEquals(wordCount("Wo r d"), 3);
- Test.assertEquals(wordCount("Bob the t-rex"), 3);
Lazy refactoring, reduced 8 if statements.
function nextGeneration(grid) { return grid.map((row, rowIndex) => { return row.map((cell, colIndex) => { if (rowIndex !== 0 && colIndex !== 0 && rowIndex < grid.length - 1 && colIndex < row.length - 1) { let neighboursCount = (grid[rowIndex][colIndex + 1] === 1) + (grid[rowIndex][colIndex - 1] === 1) + (grid[rowIndex + 1][colIndex] === 1) + (grid[rowIndex - 1][colIndex] === 1) + (grid[rowIndex + 1][colIndex + 1] === 1) + (grid[rowIndex + 1][colIndex - 1] === 1) + (grid[rowIndex - 1][colIndex + 1] === 1) + (grid[rowIndex - 1][colIndex - 1] === 1); if (cell === 1) { if (neighboursCount === 2 || neighboursCount === 3 ) { return 1; } } else { if (neighboursCount === 3 ) { return 1; } } return 0; } return 0; }); }); }
- function nextGeneration(grid) {
- return grid.map((row, rowIndex) => {
- return row.map((cell, colIndex) => {
- if (rowIndex !== 0 && colIndex !== 0 && rowIndex < grid.length - 1 && colIndex < row.length - 1) {
let neighboursCount = 0;if (grid[rowIndex][colIndex + 1] === 1) neighboursCount++;if (grid[rowIndex][colIndex - 1] === 1) neighboursCount++;if (grid[rowIndex + 1][colIndex] === 1) neighboursCount++;if (grid[rowIndex - 1][colIndex] === 1) neighboursCount++;if (grid[rowIndex + 1][colIndex + 1] === 1) neighboursCount++;if (grid[rowIndex + 1][colIndex - 1] === 1) neighboursCount++;if (grid[rowIndex - 1][colIndex + 1] === 1) neighboursCount++;if (grid[rowIndex - 1][colIndex - 1] === 1) neighboursCount++;- let neighboursCount = (grid[rowIndex][colIndex + 1] === 1) + (grid[rowIndex][colIndex - 1] === 1) + (grid[rowIndex + 1][colIndex] === 1) + (grid[rowIndex - 1][colIndex] === 1) + (grid[rowIndex + 1][colIndex + 1] === 1) + (grid[rowIndex + 1][colIndex - 1] === 1) + (grid[rowIndex - 1][colIndex + 1] === 1) + (grid[rowIndex - 1][colIndex - 1] === 1);
- if (cell === 1) {
- if (neighboursCount === 2 || neighboursCount === 3 ) {
- return 1;
- }
- } else {
- if (neighboursCount === 3 ) {
- return 1;
- }
- }
- return 0;
- }
- return 0;
- });
- });
- }
#include <functional> bool Or(bool a, bool b){ return std::logical_or<>()(a, b); } bool Xor(bool a, bool b){ return std::not_equal_to<>()(a, b); } bool And(bool a, bool b){ return std::logical_and<>()(a, b); }
- #include <functional>
- bool Or(bool a, bool b){
if(!a){if(!b){return false;}}return true;- return std::logical_or<>()(a, b);
- }
- bool Xor(bool a, bool b){
return a != b;- return std::not_equal_to<>()(a, b);
- }
- bool And(bool a, bool b){
if(a){if(b){return true;}}return false;- return std::logical_and<>()(a, b);
- }
using System; using System.Linq; public class Kumite { public static int Digits(ulong n) { //GEEEEEEET DUUUUUUNKED OOOOOOOOOOOOOON int theseDigitsShouldREALLYBeCountedImSureOfIt = n .ToString() .ToCharArray() .Select((c,i)=>new{_char = c, ShouldBeCounted = true, index = i}) .Select((a,i)=>new{charValue = a._char-'0', shouldREALLYbecounted = a.ShouldBeCounted && a.index==i}) .OrderBy(a=>a.charValue) .ToArray() .Where(a=>a.shouldREALLYbecounted.ToString()=="True") .ToList() .ToArray() .Length; int thatNameWasTooLong = theseDigitsShouldREALLYBeCountedImSureOfIt; int soWasThatOne = thatNameWasTooLong; int betterstill = soWasThatOne; int thisone = betterstill; int _this = thisone; int _ = _this; return _; } }
- using System;
- using System.Linq;
- public class Kumite
- {
// Unrolled div looppublic static int Digits(ulong n) => n.ToString().Length;- public static int Digits(ulong n)
- {
- //GEEEEEEET DUUUUUUNKED OOOOOOOOOOOOOON
- int theseDigitsShouldREALLYBeCountedImSureOfIt = n
- .ToString()
- .ToCharArray()
- .Select((c,i)=>new{_char = c, ShouldBeCounted = true, index = i})
- .Select((a,i)=>new{charValue = a._char-'0', shouldREALLYbecounted = a.ShouldBeCounted && a.index==i})
- .OrderBy(a=>a.charValue)
- .ToArray()
- .Where(a=>a.shouldREALLYbecounted.ToString()=="True")
- .ToList()
- .ToArray()
- .Length;
- int thatNameWasTooLong = theseDigitsShouldREALLYBeCountedImSureOfIt;
- int soWasThatOne = thatNameWasTooLong;
- int betterstill = soWasThatOne;
- int thisone = betterstill;
- int _this = thisone;
- int _ = _this;
- return _;
- }
- }