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 returnhundred() { let im_bored = "qwertyuiopasdfghjklzxcvbnmqwertyuioopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzx"; return im_bored.length; }
- function returnhundred() {
return 10 ** 2;- let im_bored = "qwertyuiopasdfghjklzxcvbnmqwertyuioopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzx";
- return im_bored.length;
- }
const { assert: { strictEqual } } = require('chai'); describe("100", () => it("One hundred.", () => strictEqual(returnhundred(), 100)));
// 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.Test.assertEquals(returnhundred(),100)- const { assert: { strictEqual } } = require('chai');
- describe("100", () => it("One hundred.", () => strictEqual(returnhundred(), 100)));
require 'mongoid'
File.open('mongoid.yml', 'w') do |file|
file.write <<-CONFIG
development:
sessions:
default:
database: mongoid
hosts:
- localhost:27017
CONFIG
end
fork do
exec 'mongod'
end
sleep 1 # need to find a better way to wait for mongo to startup
ENV['RACK_ENV'] = 'development'
Mongoid.load!('mongoid.yml')
class User
include Mongoid::Document
field :name
end
describe User do
it 'should save' do
Test.expect(User.new.save)
Test.assert_equals(User.count, 1)
end
end
Spawning a more complex function as a process.
Proc = fun(Y, Items) ->
receive
Item when is_atom(Item) ->
io:format("~p added.~n", [Item]),
Y(Y, [Item | Items]);
_ -> io:format("Killing Fridge...")
end
end,
Pid = spawn(fun() -> Proc(Proc, []) end),
Pid ! beer,
Pid ! salsa,
Pid ! soda,
Pid ! eggs,
Pid ! steak,
Pid ! pudding,
init:stop().
Proc = fun () ->
io:format("Hello Process.~n")
end,
Pid = spawn(Proc),
io:format(" Hello's Pid: ~p~n", [Pid]),
init:stop().
Javascript function-based Array 'syntax':
This is an interesting kata that I came across today*, in which a function was called in this kind of fashion, previously unseen by me:
someFunction(6)()()(2)()()(1).end(); // Wierd, right?
To an experienced JavaScripter, this will immediately seem clear: The function is returning another function, that returns itself, and has a method end()
to 'terminate' the chain.
Interested by this, I made this kumite describing a similar function that would create an Array. I also changed end
to a variable rather than a function, because one, I'm addicted to ruby** syntax, and two, it's generally easier on the fingers!
// 'chain(arg)...(arg).end;' is equivalent to '[arg...arg];'
chain().end; // [null]
chain(1)(2)(3).end // [1, 2, 3]
chain('hey')()(true).end // ['hey', null ,true]
Suggestions for future forks:
-
Improve the syntax further: Add a bit of syntax to describe repetition of an element, maybe
chain(6)(3,2)(6) => [6,3,3,6]
? - Make this in other languages: Is it possible? How, or why not?
- Refactor this code: I'm pretty sure I've got this nailed, but I'd still like to see how other people do it!
* This kumite was inspired by this kata, which I really reccomend having a shot at.
** I can't seem to create a Ruby equivalent, If you work out how, please make a fork!
// This is just an interesting alternative way to build an array,
// almost like a declarative literal - Very cool stuff!
// See test cases for syntax.
function chain(element) {
var array = [element];
var sectionBuilder = function(elem) {
array.push(elem);
sectionBuilder.end = array;
return sectionBuilder;
};
sectionBuilder.end = array;
return sectionBuilder;
}
// buildArray(6)(9)(12)(2)(7).end; => [6,9,12,2,7]
// buildArray('6')(1)(true)(7).end; => ['6',1,true,7]
Test.assertSimilar( chain(6)(8)(12)(2)(7).end, [6,8,12,2,7], "Similarity test failed." )
Test.assertSimilar( chain('6')(1)(true)(7).end, ['6',1,true,7] )
Test.assertSimilar( chain(null).end, [null] )
// Going further, how would you create a random Array function using this method?