Start a new Kumite
AllAgda (Beta)BF (Beta)CCFML (Beta)ClojureCOBOL (Beta)CoffeeScriptCommonLisp (Beta)CoqC++CrystalC#D (Beta)DartElixirElm (Beta)Erlang (Beta)Factor (Beta)Forth (Beta)Fortran (Beta)F#GoGroovyHaskellHaxe (Beta)Idris (Beta)JavaJavaScriptJulia (Beta)Kotlinλ Calculus (Beta)LeanLuaNASMNim (Beta)Objective-C (Beta)OCaml (Beta)Pascal (Beta)Perl (Beta)PHPPowerShell (Beta)Prolog (Beta)PureScript (Beta)PythonR (Beta)RacketRaku (Beta)Reason (Beta)RISC-V (Beta)RubyRustScalaShellSolidity (Beta)SQLSwiftTypeScriptVB (Beta)
Show only mine

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.

Ad
Ad

Validate a porperty in object

function validateProperty(objectForValidate, specificProperty) {
  if(objectForValidate[specificProperty]){
    return true;
  } else{
    return false;
  }
}

Validate a property in object

function validateProperty(objectForValidate, specificProperty) {
  if(objectForValidate[specificProperty]){
    return true;
  } else{
    return 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 ""

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'

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!"
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;
}

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"

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

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}`
}

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