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
Algorithms
Logic

This slight shuffle makes the function more robust when given non-array values. Not sure that's a desirable feature :-/

Code
Diff
  • const flatten = a => 
      Array.isArray(a) ? a.reduce((acc,item) => acc.concat(flatten(item)), []) : a;
    • const flatten = arr =>
    • arr.reduce((acc, item) => acc.concat(Array.isArray(item) ? flatten(item) : item), []);
    • const flatten = a =>
    • Array.isArray(a) ? a.reduce((acc,item) => acc.concat(flatten(item)), []) : a;
Code
Diff
  • using System;
    
    namespace Solution {
    
      class FizzBuzz {
        public static Func<int, string> convert = (input) 
                => {
                  var output = $"{input % 3 == 0 ? "Fizz" : string.Empty}{input % 5 == 0 ? "Buzz" : string.Empty}";
                  return !string.IsNullOrWhiteSpace(output) ? output : input.ToString();
                };
      }
    }
    • using System;
    • namespace Solution {
    • class FizzBuzz {
    • public static string convert(int input)
    • {
    • var output = (input % 3 == 0 ? "Fizz" : "") + (input % 5 == 0 ? "Buzz" : "");
    • return output == "" ? input.ToString() : output;
    • }
    • public static Func<int, string> convert = (input)
    • => {
    • var output = $"{input % 3 == 0 ? "Fizz" : string.Empty}{input % 5 == 0 ? "Buzz" : string.Empty}";
    • return !string.IsNullOrWhiteSpace(output) ? output : input.ToString();
    • };
    • }
    • }

changed id to string and check if result of the custom unique-method is correct

the problem now is, that the groovy-unique-method is not that slow as before....

Regular Expressions
Declarative Programming
Advanced Language Features
Programming Paradigms
Fundamentals
Strings

This regular expression is a little lack luster. I think it could be improved to account for hyphens and apostraphes that are supposed to be apart of a word. The objective here is to not accidentally capture punctuation mistakes.

Code
Diff
  • wordCount=s=>s.trim().match(/[A-Za-z0-9]+/mg).length;
    • wordCount=s=>s.trim().split(' ').length
    • wordCount=s=>s.trim().match(/[A-Za-z0-9]+/mg).length;
Algorithms
Logic
Code
Diff
  • const getDividors = n => {
      
      let result = [];
    
      for (let i = 1; i <= Math.floor(Math.sqrt(n)); i += 1)
        if (n % i === 0) { result.push(i); if (n / i !== i) result.push(n / i) }
        
      return result; // output array won't be sorted
      
    }
    • const getDividors = (n, result = []) => {
    • const getDividors = n => {
    • let result = [];
    • for (let i = 1; i <= Math.floor(Math.sqrt(n)); i++)
    • for (let i = 1; i <= Math.floor(Math.sqrt(n)); i += 1)
    • if (n % i === 0) { result.push(i); if (n / i !== i) result.push(n / i) }
    • return result; // output array won't be sorted
    • }
Search
Algorithms
Logic

Now it's even more prettier

Code
Diff
  • import java.util.*;
    
    class Node {
      int value;
      Node left;
      Node right;
      
      public Node(int value) {
        this.value = value;
      }
    }
    
    
    class BST {
      public static boolean search(Node root, int key) {   
          if (root == null)
            return false;
          if (root.value == key)
            return true;
          
          return root.value > key ? search(root.left, key) : search(root.right, key); 
      }
    }
    • import java.util.*;
    • class Node {
    • int value;
    • Node left;
    • Node right;
    • public Node(int value) {
    • this.value = value;
    • }
    • }
    • class BST {
    • public static boolean search(Node root, int key) {
    • if (root == null){
    • return false;
    • }else if(root.value == key) {
    • if (root == null)
    • return false;
    • if (root.value == key)
    • return true;
    • } else{
    • return root.value > key ? search(root.left, key) : search(root.right, key);
    • }
    • return root.value > key ? search(root.left, key) : search(root.right, key);
    • }
    • }