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.
Validate a porperty in object
function validateProperty(objectForValidate, specificProperty) {
if(objectForValidate[specificProperty]){
return true;
} else{
return false;
}
}
describe("Validate property in object", function(){
it("should be return true when the property exists", function(){
const test = { a: 2 };
const validation = validateProperty(test, 'a');
Test.assertEquals(validation, true);
});
it("should be return false when the property not exists", function(){
const test = {};
const validation = validateProperty(test, 'a');
Test.assertEquals(validation, false);
});
it("should be return false when the property is equals to empty", function(){
const test = { a: '' };
const validation = validateProperty(test, 'a');
Test.assertEquals(validation, false);
});
});
Validate a property in object
function validateProperty(objectForValidate, specificProperty) {
if(objectForValidate[specificProperty]){
return true;
} else{
return false;
}
}
describe("Validate property in object", function(){
it("should be return true when the property exists", function(){
const test = { a: 2 };
const validation = validateProperty(test, 'a');
Test.assertEquals(validation, true);
});
it("should be return false when the property not exists", function(){
const test = {};
const validation = validateProperty(test, 'a');
Test.assertEquals(validation, false);
});
it("should be return false when the property is equals to empty", function(){
const test = { a: '' };
const validation = validateProperty(test, 'a');
Test.assertEquals(validation, false);
});
});
List of packages recently added
-
parsec
,attoparsec
,megaparsec
-
hspec-attoparsec
,hspec-megaparsec
-
regex-pcre
,regex-tdfa
,regex-posix
List of packages tested here
parsec
regex-*
module Example where
import qualified Text.Regex.Posix as Posix
import qualified Text.Regex.PCRE as PCRE
import qualified Text.Regex.TDFA as TDFA
import Text.Parsec
import Text.Parsec.Char
import Text.Parsec.String
-- The most basic functionalities of Regex modules
posixMatches :: String -> String -> Bool
posixMatches = (Posix.=~)
pcreMatches :: String -> String -> Bool
pcreMatches = (PCRE.=~)
tdfaMatches :: String -> String -> Bool
tdfaMatches = (TDFA.=~)
pcreVersion :: Maybe String
pcreVersion = PCRE.getVersion
-- The most basic functionalities of Parsec
number :: Parser Integer
number = (\a b -> read a) <$> many1 digit <*> eof
parseInt :: String -> Either ParseError Integer
parseInt = parse number ""
module ExampleSpec where
import Data.Maybe
import Data.Either
import Test.Hspec
import Example
-- `spec` of type `Spec` must exist
spec :: Spec
spec = do
describe "regex" $ do
it "PCRE version should be available" $ do
pcreVersion `shouldSatisfy` isJust
it "Each flavor should work as intended" $ do
posixMatches "baaab" "a+b" `shouldBe` True
posixMatches "aaacb" "a+b" `shouldBe` False
pcreMatches "baaab" "a+b" `shouldBe` True
pcreMatches "aaacb" "a+b" `shouldBe` False
tdfaMatches "baaab" "a+b" `shouldBe` True
tdfaMatches "aaacb" "a+b" `shouldBe` False
describe "parsec" $ do
it "Parsec should work as intended" $ do
parseInt "a" `shouldSatisfy` isLeft
parseInt "123456" `shouldBe` Right 123456
parseInt "123456 " `shouldSatisfy` isLeft
-- the following line is optional for 8.2
main = hspec spec
List of packages tested
megaparsec
hspec-megaparsec
If you can build a working attoparsec
example, please post a kumite on it.
module Example where
import Text.Megaparsec
import Text.Megaparsec.Char
import Data.Void
type Parser = Parsec Void String
singleX :: Parser Char
singleX = char 'x'
module ExampleSpec where
import Test.Hspec
import Test.Hspec.Megaparsec
import Text.Megaparsec
import Example
spec :: Spec
spec = do
describe "megaparsec" $ do
it "works as intended" $ do
parse singleX "" `shouldSucceedOn` "x"
-- the following line is optional for 8.2
main = hspec spec
PureScript is a strongly, statically typed functional programming language that compiles to and is easily interoperable with JavaScript. Its syntax and semantics are heavily influenced by Haskell so Haskell enthusiasts should find it easy to pick up PureScript.
Please don't forget to help PureScript leave Beta on Codewars and support the Codewars PureScript community by completing, authoring and translating more PureScript Kata. - @donaldsebleung
module WelcomePureScript (welcomeMsg) where
welcomeMsg :: String
welcomeMsg = "Welcome, PureScript!"
module ExampleSpec where
import Prelude
import Test.Spec (Spec, describe, it)
import Test.Spec.Assertions (shouldEqual)
import WelcomePureScript (welcomeMsg)
spec :: Spec Unit
spec =
describe welcomeMsg do
it "PureScript is a strongly and statically typed functional programming language that compiles to and is easily interoperable with JavaScript." do
welcomeMsg `shouldEqual` welcomeMsg
it "Its syntax and semantics are heavily influenced by Haskell so Haskell programmers should find it easy to pick up PureScript." do
welcomeMsg `shouldEqual` welcomeMsg
it "Please don't forget to help PureScript leave Beta on Codewars and support the Codewars PureScript community by completing, authoring and translating more PureScript Kata. - @donaldsebleung" do
welcomeMsg `shouldEqual` welcomeMsg
function digitizeNumber(number) {
let digits = [];
let stringNumber = number && number.toString() || "";
for (let i = 0; i < stringNumber.length; i += 1) {
digits.push(+stringNumber.charAt(i));
}
return digits;
}
// 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();
describe("Solution", function(){
it("should test for something", function(){
Test.expect(digitizeNumber(123456), [1,2,3,4,5,6]);
Test.expect(digitizeNumber(0), []);
Test.expect(digitizeNumber(undefined), []);
Test.expect(digitizeNumber(90124), [9,0,1,2,4]);
Test.expect(digitizeNumber(123456), [1, 2, 3, 4, 5, 6]);
Test.expect(digitizeNumber(-123), [NaN, 1, 2, 3]);
});
});
Just testing whether arbitrary-precision integers in PureScript are supported on Codewars. See the tests for the results.
module BigIntExample where
import Prelude
import Data.BigInt (BigInt, fromString)
import Data.Maybe (fromJust)
import Partial.Unsafe (unsafePartial)
biiiig :: BigInt
biiiig = unsafePartial fromJust $ fromString "917389127398375893457348957389457128937189237189237894357389457438957348957348957348947128937128937128937"
module ExampleSpec where
import Prelude
import Test.Spec (Spec, describe, it)
import Test.Spec.Assertions (shouldEqual)
import BigIntExample (biiiig)
spec :: Spec Unit
spec =
describe "Is Data.BigInt available on Codewars?" do
describe "Let's see" do
it "This should compile with passed tests if it is indeed supported." do
true `shouldEqual` true
Just a test to see whether Data.Ratio
for PureScript is available on Codewars. See test output for results.
module RatioExample where
import Prelude
import Data.Ratio
myRatio :: Ratio Int
myRatio = 3 % 10 -- 3 to 10, or 0.3
module ExampleSpec where
import Prelude
import Test.Spec (Spec, describe, it)
import Test.Spec.Assertions (shouldEqual)
import RatioExample (myRatio)
spec :: Spec Unit
spec =
describe "Is Data.Ratio in PureScript available on Codewars?" do
describe "Let us see ... " do
it "This should compile with passed tests if it is indeed supported." do
true `shouldEqual` true
Given any number (let's say up to the billions). It should convert that number into an English text string.
See the test cases for more information
const getUnits = number => ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'][number] || ''
const getTens = (tens, units) => tens === 1
? ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'][units]
: ['', '', 'twenty ', 'thirty ', 'fourty ', 'fifty ', 'sixty ', 'seventy ', 'eighty ', 'ninety '][tens] + getUnits(units)
const getLargeNumber = number => ['', 'thousand ', 'million ', 'billion '][number]
const convertThreeDigits = (numeral, more) => {
const tensNumber = getTens(~~((numeral % 100) / 10), (numeral % 100) % 10)
const hundredsNumber = getUnits(~~(numeral / 100)) ? getUnits(~~(numeral / 100)) + ' hundred ' : ''
const and = (hundredsNumber || more) && tensNumber ? 'and ' : ''
return `${hundredsNumber}${and}${tensNumber}`.trim()
}
const buildText = (remaining, index = 0) => {
if (remaining < 1000) return `${convertThreeDigits(remaining)} ${getLargeNumber(index)}`
return `${buildText(~~(remaining / 1000), index + 1)}${convertThreeDigits(remaining % 1000, remaining / 1000)}`
}
function numToText(numeral) {
if (numeral === 0) return 'zero'
const text = buildText(Math.abs(numeral)).trim()
return numeral < 0 ? `minus ${text}` : `${text}`
}
var expect = require("chai").expect;
require("chai").should();
describe('numToText converts numbers to text', () => {
describe('units', () => {
[
{ input: 0, actual: 'zero' },
{ input: 1, actual: 'one' },
{ input: 2, actual: 'two' },
{ input: 3, actual: 'three' },
{ input: 4, actual: 'four' },
{ input: 5, actual: 'five' },
{ input: 6, actual: 'six' },
{ input: 7, actual: 'seven' },
{ input: 8, actual: 'eight' },
{ input: 9, actual: 'nine' }
].forEach(({ input, actual }) => {
it(`should convert ${input} to ${actual}`, () => {
expect(numToText(input)).to.equal(actual)
})
})
})
describe('tens', () => {
describe('teens', () => {
[
{ input: 10, actual: 'ten' },
{ input: 11, actual: 'eleven' },
{ input: 12, actual: 'twelve' },
{ input: 13, actual: 'thirteen' },
{ input: 14, actual: 'fourteen' },
{ input: 15, actual: 'fifteen' },
{ input: 16, actual: 'sixteen' },
{ input: 17, actual: 'seventeen' },
{ input: 18, actual: 'eighteen' },
{ input: 19, actual: 'nineteen' }
].forEach(({ input, actual }) => {
it(`should convert ${input} to ${actual}`, () => {
expect(numToText(input)).to.equal(actual)
})
})
})
describe('just the tens', () => {
[
{ input: 20, actual: 'twenty' },
{ input: 30, actual: 'thirty' },
{ input: 40, actual: 'fourty' },
{ input: 50, actual: 'fifty' },
{ input: 60, actual: 'sixty' },
{ input: 70, actual: 'seventy' },
{ input: 80, actual: 'eighty' },
{ input: 90, actual: 'ninety' }
].forEach(({ input, actual }) => {
it(`should convert ${input} to ${actual}`, () => {
expect(numToText(input)).to.equal(actual)
})
})
})
describe('tens and units', () => {
it('should return twenty one when passed 21', () => {
expect(numToText(21)).to.equal('twenty one')
})
it('should return ninety nine when passed 99', () => {
expect(numToText(99)).to.equal('ninety nine')
})
})
})
describe('hundreds', () => {
describe('just hundreds', () => {
it('should return one hundred when passed 100', () => {
expect(numToText(100)).to.equal('one hundred')
})
it('should return two hundred when passed 200', () => {
expect(numToText(200)).to.equal('two hundred')
})
})
describe('any three digit number', () => {
it('should return one hundred twenty three given 123', () => {
expect(numToText(123)).to.equal('one hundred and twenty three')
})
it('should return five hundred twelve given 512', () => {
expect(numToText(512)).to.equal('five hundred and twelve')
})
it('should return seven hundred one given 701', () => {
expect(numToText(701)).to.equal('seven hundred and one')
})
})
})
describe('thousands', () => {
it('should return seven thousand two hundred nineteen given 7219', () => {
expect(numToText(7219)).to.equal('seven thousand two hundred and nineteen')
})
it('should return three hundred four thousand two hundred twenty one given 304221', () => {
expect(numToText(304221)).to.equal('three hundred and four thousand two hundred and twenty one')
})
})
describe('very large numbers', () => {
[
{ input: 1000000, output: 'one million' },
{ input: 452000000001, output: 'four hundred and fifty two billion and one' },
{ input: 100000000100, output: 'one hundred billion one hundred' }
].forEach(({ input, output }) => {
it(`should convert ${input} to ${output}`, () => {
expect(numToText(input)).to.equal(output)
})
})
})
describe('negatives', () => {
it('should do negative numbers', () => {
expect(numToText(-1)).to.equal('minus one')
})
})
})
Write a function that returns a number if its factorial is given.
If the input value does not have a solution, return 0.
Example:
input : 120
output : 5
def reverse_fact(input):
prod = 1
i = 1
while True:
if input % i == 0:
prod *= i
if prod == input:
return i
else:
return 0
i += 1
test.assert_equals(reverse_fact(24), 4)
test.assert_equals(reverse_fact(120), 5)
test.assert_equals(reverse_fact(362880), 9)
test.assert_equals(reverse_fact(1), 1)
test.assert_equals(reverse_fact(25), 0)