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.
let results = [ {materia: {conteudo: {titulo: 'São Paulo'}}, tags: [1, 2, 3]}, {materia: {conteudo: {}}, tags: [3, 2]}, {materia: {conteudo: {titulo: 'Rio de Janeiro'}}, tags: [3, 2]}, ]; for (const {materia: {conteudo: {titulo = 'Brasil'}}} of results){ console.log(titulo); }
- let results = [
- {materia: {conteudo: {titulo: 'São Paulo'}}, tags: [1, 2, 3]},
- {materia: {conteudo: {}}, tags: [3, 2]},
- {materia: {conteudo: {titulo: 'Rio de Janeiro'}}, tags: [3, 2]},
- ];
for (const result of results) {let titulo = result.materia.conteudo.titulo || 'Brasil';console.log(titulo);- for (const {materia: {conteudo: {titulo = 'Brasil'}}} of results){
- console.log(titulo);
- }
Converts a number to English. This is a horrendous mess...
(ns number-to-words
(:require [clojure.string :refer [join]]))
(def digit-to-word
{1 "One"
2 "Two"
3 "Three"
4 "Four"
5 "Five"
6 "Six"
7 "Seven"
8 "Eight"
9 "Nine"})
(def tens-to-word
{
20 "Twenty"
30 "Thirty"
40 "Fourty"
50 "Fifty"
60 "Sixty"
70 "Seventy"
80 "Eighty"
90 "Ninety"})
(def teen-to-word
{10 "Ten"
11 "Eleven"
12 "Twelve"
13 "Thirteen"
14 "Fourteen"
15 "Fifteen"
16 "Sixteen"
17 "Seventeen"
18 "Eighteen"
19 "Nineteen"})
(defn- small-number-to-words
[x]
(cond
(<= x 9) (digit-to-word x)
(< x 20) (teen-to-word x)
(< x 100)
(let [ones-part (mod x 10)
tens-part (- x ones-part)]
(str (tens-to-word tens-part) "-"
(digit-to-word ones-part)))
(<= x 999)
(let [small-part (mod x 100)
hundreds-digit (-> x (- small-part) (/ 100))]
(str (digit-to-word hundreds-digit) " Hundred " (small-number-to-words small-part)))))
(defn- digit-shift
[x shift]
(-> x (- (mod x shift)) (/ shift) int))
(defn convert
[x]
(loop [words [] x x]
(cond
(-> x (>= 1e6))
(recur (conj words "One Million")
(- x 1e6))
(-> x (>= 1e3))
(recur (conj words
(str
(-> x (digit-shift 1000) small-number-to-words)
" Thousand"))
(mod x 1000))
(-> x (> 0))
(recur (conj words (small-number-to-words x)) 0)
:else (join ", " words))))
(ns number-to-word-test
(:require [clojure.test :refer :all]
[number-to-words]))
(deftest conversion-test
(is (= "One Million" (number-to-words/convert 1e6)))
(is (= "Nine Hundred Ninety-Nine Thousand" (number-to-words/convert 999e3))
(is (= "Six Hundred Twelve Thousand, Three Hundred Twenty-Three" (number-to-words/convert 612323)))))
const firstNonRepeatingCharacter = str => { const obj = [...str].reduce((a,c) => {a[c]?a[c]++:a[c]=1;return a},{}); return Object.keys(obj).find(e => obj[e]===1)||null; };
const firstNonRepeatingCharacter = (str) => {for (let i = 0; i < str.length; i++) {let seenDuplicate = false;for (let j = 0; j < str.length; j++) {if (str[i] === str[j] && i !== j) {seenDuplicate = true;break;}}if (!seenDuplicate) {return str[i];}}return null; // return null if no unique character is found- const firstNonRepeatingCharacter = str => {
- const obj = [...str].reduce((a,c) => {a[c]?a[c]++:a[c]=1;return a},{});
- return Object.keys(obj).find(e => obj[e]===1)||null;
- };
fn sum(arr: &[i32]) -> i32 { match arr.is_empty() { true => 0, false => arr[..].iter().sum::<i32>(), } }
def sum(arr):result = 0for i in arr:result += ireturn result- fn sum(arr: &[i32]) -> i32 {
- match arr.is_empty() {
- true => 0,
- false => arr[..].iter().sum::<i32>(),
- }
- }
#[cfg(test)] mod test { use super::*; #[test] fn test_sum() { assert_eq!(sum(&[1, 2, 3]), 6); } #[test] fn test_empty_sum() { assert_eq!(sum(&[]), 0); } }
import codewars_test as test# TODO Write testsfrom solution import sum- #[cfg(test)]
- mod test {
- use super::*;
- #[test]
- fn test_sum() {
- assert_eq!(sum(&[1, 2, 3]), 6);
- }
- #[test]
- fn test_empty_sum() {
- assert_eq!(sum(&[]), 0);
- }
# test.assert_equals(actual, expected, [optional] message)@test.describe("Example tests")def test_group():@test.it("Basic tests")def test_case():test.assert_equals(sum([1]), 1)test.assert_equals(sum([1,2,3]), 6)- }
digitToText = d => ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'][d]
const nums = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']function digitToText(digit) {return nums[digit]}- digitToText = d => ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'][d]
const MEANING_OF_LIFE: i32 = 42;
def meaning_of_life_is():return """go crazy with your imagination and return anything you like.strings, numbers, ... just don't return None.may the most creative answer win"""- const MEANING_OF_LIFE: i32 = 42;
#[test] fn test() { assert_eq!(MEANING_OF_LIFE, 42); }
import codewars_test as test# TODO Write testsfrom solution import meaning_of_life_is # or from solution import example# test.assert_equals(actual, expected, [optional] message)@test.describe("Example")def test_group():@test.it("test case")def test_case():test.assert_not_equals(meaning_of_life_is(), None)- #[test]
- fn test() {
- assert_eq!(MEANING_OF_LIFE, 42);
- }