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.
// Exercício 1 const titulo = "UOL - O melhor conteúdo"; // Exercício 2 const tags = [] tags.push(...['A', 'B']); // Exercício 3 let descricao = "Em 1999"; descricao += " em São Paulo"; // Exercício 4 const materia = {titulo: "Barão de Limeira"}; materia.titulo = "Alameda " + materia.titulo; // Exercício 5 for (let i = 10; i--;) { console.log(i); } // Exercício 6 for (const tag of ['A', 'B']) { console.log(tag); } // Exercício 7 for (var j = [].length; j--;) {} if (j === -1) { console.log('Não encontrei'); } // Exercício 8 let a = 123; { a *= 2; } console.log(a); // Exercício 9 let state = 'active'; function stop() { state = 'paused'; } stop(); // Exercício 10 const TRUE = !0;
- // Exercício 1
var titulo = "UOL - O melhor conteúdo";- const titulo = "UOL - O melhor conteúdo";
- // Exercício 2
var tags = []- const tags = []
- tags.push(...['A', 'B']);
- // Exercício 3
var descricao = "Em 1999";- let descricao = "Em 1999";
- descricao += " em São Paulo";
- // Exercício 4
var materia = {titulo: "Barão de Limeira"};- const materia = {titulo: "Barão de Limeira"};
- materia.titulo = "Alameda " + materia.titulo;
- // Exercício 5
for (var i = 10; i--;) {- for (let i = 10; i--;) {
- console.log(i);
- }
- // Exercício 6
for (var tag of ['A', 'B']) {- for (const tag of ['A', 'B']) {
- console.log(tag);
- }
- // Exercício 7
- for (var j = [].length; j--;) {}
- if (j === -1) {
- console.log('Não encontrei');
- }
- // Exercício 8
var a = 123;- let a = 123;
- {
- a *= 2;
- }
- console.log(a);
- // Exercício 9
var state = 'active';- let state = 'active';
- function stop() {
- state = 'paused';
- }
- stop();
- // Exercício 10
var TRUE = !0;- const TRUE = !0;
Different way wihout using reduce
and forEach
.
import java.util.*; class Solution { public static String largestNumber(final Integer[] nums) { Arrays.sort(nums, new Comparator<Integer>() { @Override public int compare(final Integer a, final Integer b) { return (""+b+a).compareTo(""+a+b); } }); String result = ""; for (final Integer num : nums) { result += num; } return result; } }
- import java.util.*;
- class Solution {
public static String largestNumber(Integer[] nums) {Arrays.sort( nums, new Comparator<Integer>() {- public static String largestNumber(final Integer[] nums) {
- Arrays.sort(nums, new Comparator<Integer>() {
- @Override
public int compare(Integer a, Integer b) {String aStr = a.toString();String bStr = b.toString();return (aStr + bStr).compareTo(bStr + aStr) * -1;- public int compare(final Integer a, final Integer b) {
- return (""+b+a).compareTo(""+a+b);
- }
} );- });
- String result = "";
for(Integer num : nums) {result += num.toString();- for (final Integer num : nums) {
- result += num;
- }
- return result;
- }
- }
Array#flip method:
This kumite is a script that "flips" an Array's contents. Rather than simply Array#reverse
it. Here's an example:
[1,2,3,[4,5,6],7,8,9].reverse #=> [9,8,7,[4,5,6],3,2,1]
[1,2,3,[4,5,6],7,8,9].flip #=> [9,8,7,[6,5,4],3,2,1]
# ^
It's as if you've physically turned around an array. This goes for any smaller arrays within the Array given, so recursion may be on the cards.
I've done a neat little script (If you don't mind me saying!) carrying out this task. Please feel free to refactor, comment and feedback; I find critisism indispensible.
As a sidenote, maybe we could implement this for Hash as well? Maybe {:hello => "world"}
should become {"world" => :hello}
?
class Array # Opens up the Array class for method creation
def flip
result = []
me = self.reverse # Don't fret, I'll sort the Arrays out!
me.each do |x|
if x.class == Array then result << x.flip # Here's the recursion.
else result << x
end
end
return result
end
end
describe "Array#flip Kumite" do
it "should have Array#flip defined" do
Test.expect defined?([1,2,3,4,5].flip), "Array#flip is not defined."
Test.assert_equals [1,2,3,4,5].flip, [5,4,3,2,1]
Test.assert_equals [1,2,[3,4],5].flip, [5,[4,3],2,1]
Test.assert_equals [1,2,[3,4,[5,6],7],8,[9,10]].flip, [[10,9],8,[7,[6,5],4,3],2,1]
end
end
def Complicated_Greetings(name): h=["H","e","l","l","o"] c="," w=["W","o","r","l","d"] e="!" k="".join(h) if name=="": k+=c k+=" " k+="".join(w) k+=e*2 else: k+=" " k+=name return k
- def Complicated_Greetings(name):
- h=["H","e","l","l","o"]
- c=","
- w=["W","o","r","l","d"]
- e="!"
k=""for i in h:k+=i- k="".join(h)
- if name=="":
- k+=c
- k+=" "
for i in w:k+=ik=k+e+e- k+="".join(w)
- k+=e*2
- else:
- k+=" "
- k+=name
- return k
function rgbToHsv(rgb) { let r = rgb[0] / 255, g = rgb[1] / 255, b = rgb[2] / 255; const v = Math.max(r, g, b); const min = Math.min(r, g, b); const delta = v - min; const s = v === 0 ? 0 : delta / v; let h = 0; if (delta !== 0) { if (v === r) { h = (g - b) / delta + (g < b ? 6 : 0); } else if (v === g) { h = (b - r) / delta + 2; } else { h = (r - g) / delta + 4; } h /= 6; h *= 360; } return [Math.round(h), Math.round(s * 100), Math.round(v * 100)]; }
- function rgbToHsv(rgb) {
let r = rgb[0], g = rgb[1], b = rgb[2];const v = Math.max(r, g, b) / 255;if (v == 0) return Array.of(0, 0, 0);r /= v;g /= v;b /= v;const s = 1 - Math.min(r, g, b) / 255;if (s == 0) return Array.of(0, 0, v * 100);r = 255 - (255 - r) / s;g = 255 - (255 - g) / s;b = 255 - (255 - b) / s;const peak = Math.max(r, g, b);- let r = rgb[0] / 255, g = rgb[1] / 255, b = rgb[2] / 255;
- const v = Math.max(r, g, b);
- const min = Math.min(r, g, b);
- const delta = v - min;
- const s = v === 0 ? 0 : delta / v;
- let h = 0;
if (r == peak) h = g < b ? 360 - b * 60 / 255 : g * 60 / 255;else if (g == peak) h = r > b ? 120 - r * 60 / 255 : 120 + b * 60 / 255;else h = r > g ? 240 + r * 60 / 255 : 240 - g * 60 / 255;return Array.of(Math.round(h), Math.round(s * 100), Math.round(v * 100));- if (delta !== 0) {
- if (v === r) {
- h = (g - b) / delta + (g < b ? 6 : 0);
- } else if (v === g) {
- h = (b - r) / delta + 2;
- } else {
- h = (r - g) / delta + 4;
- }
- h /= 6;
- h *= 360;
- }
- return [Math.round(h), Math.round(s * 100), Math.round(v * 100)];
- }
fn riddle(word: &str) -> usize { word.trim_matches(|c: char| !c.is_ascii_alphabetic()).len() }
def riddle(word):return len(word) - 1- fn riddle(word: &str) -> usize {
- word.trim_matches(|c: char| !c.is_ascii_alphabetic()).len()
- }
#[test] fn test() { assert_eq!(riddle("Two?"), 3); assert_eq!(riddle("Ten?"), 3); assert_eq!(riddle("Three?"), 5); assert_eq!(riddle("Four..."), 4); assert_eq!(riddle("¡Twelve!"), 6); assert_eq!(riddle("Four..."), 4); }
test.assert_equals(riddle("Two?"), 3)test.assert_equals(riddle("Ten?"), 3)test.assert_equals(riddle("Three?"), 5)- #[test]
- fn test() {
- assert_eq!(riddle("Two?"), 3);
- assert_eq!(riddle("Ten?"), 3);
- assert_eq!(riddle("Three?"), 5);
- assert_eq!(riddle("Four..."), 4);
- assert_eq!(riddle("¡Twelve!"), 6);
- assert_eq!(riddle("Four..."), 4);
- }