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

Get sum of elements of array using Array.reduce function

/* Array.reduce(
 * (accumulator, currentValue, currentIndex, array) => {
 * return accumulator + currentValue;
 * },
 * initialValue
 * );
 */
function sumOfElements(arr) {
  if(arguments.length === 0)
    arr = [1,2,3,4,5];
  
  var total = arr.reduce( (sum, currentValue) => {return sum + currentValue}, 0 );
  
  console.log(total);
  return total;
}

Jake's girlfriend just told him she wants to go gluten-free. And she wants him to build a Javascript function to help them detect gluten in their favorite foods. I know, the request is a little weird, but why not help him?

The code should take a list of ingredients and detect whether or not it contains the following:

  "wheat",
  "wheat flour",
  "triticale",
  "barley",
  "rye",
  "brewer's yeast",
  "malt",
  "wheatberries",
  "durum",
  "emmer",
  "semolina",
  "spelt",
  "farina",
  "farro",
  "graham",
  "kamut",
  "einkorn"
  
function glutenDetector(ingredients){
  var gluten = [
  "wheat",
  "wheat flour",
  "triticale",
  "barley",
  "rye",
  "brewer's yeast",
  "malt",
  "wheatberries",
  "durum",
  "emmer",
  "semolina",
  "spelt",
  "farina",
  "farro",
  "graham",
  "kamut",
  "einkorn"
  ];
  var glutenDetect = false; 
  var ingredientsList = ingredients.split(',');
  ingredientsList.forEach(function(ingredient){
    var ingredientClean = ingredient.trim().toLowerCase();
    gluten.forEach(function(glutenIngredient){
      if(ingredientClean.indexOf(glutenIngredient) !== -1){
        glutenDetect = true;
      }
    });

  });

  return glutenDetect;
  
}

The .unique() method for lists is super slow in Groovy, make it as fast as possible

class Uniquer {
  static List unique(List x) {
    x.groupBy { it }.keySet().collect()
  }
}

We are adding a new bus provider to our system. In order to implement a very specific requirement of this bus provider our system needs to be able to filter direct connections. We have access to a weekly updated list of bus routes in form of a bus route data file. As this provider has a lot of long bus routes, we need to come up with a proper service to quickly answer if two given stations are connected by a bus route.

public class HelloBus {
}
(defun say-hello ()
  (tagbody
        (setq i 5)
   start
        (format t "[+] Hello there!~%")
        (decf i)
        (go end)
   end
        (and (zerop i) (return-from say-hello "this end."))
        (go start)
   ))
// const request = require('request');

// function getUserAllies(username){
//   return new Promise(function(resolve, reject){
//     request('https://www.codewars.com/users/'+username, function(err, res, body){
//       let html = body;
//       let allies = (html.match(/<div class=\"stat\"><b>Allies:<\/b>(\d+)<\/div>/) || [,'null match'])[1];
//       resolve(+allies);
//     });
//   });
// }

// using request-promise to avoid wrapping a Promise
const rp = require('request-promise');

function getUserAllies(username){
  return rp('https://www.codewars.com/users/'+username).then(function(body){
    let html = body;
    let allies = (html.match(/<div class=\"stat\"><b>Allies:<\/b>(\d+)<\/div>/) || [,'null match'])[1];
    return(+allies);
  });
}

This extension add a shuffled() method to any sequence.

References:

import Foundation 

extension Sequence {
  func shuffled() -> [Iterator.Element] {
    return Array(self).sorted { _,_ in drand48() < drand48() }
  }
}

// [Int] -> [Int]
print([1,2,3,4,5,6].shuffled())

// CountableClosedRange<Int> -> [Int]
print((1...6).shuffled())
function hello() {
  return "world";
}

Note

  • random() is not available in Swift 4.0
import Glibc // for random()

let a = random()

print(a)
#include <algorithm>

template< class T >
void Swap( T& a, T& b ) { std::swap( a, b ); }