Skip to content

C# Katas 👷🏼‍♂️👷🏼‍♀️

Exes and Ohs

using System.Linq;
public static class Kata
{
    public static bool XO (string input)
    {
        return input.Where(chr => chr=='X' || chr=='x').Count() == input.Where(chr => chr=='O' || chr=='o').Count();
    }
}

Invert values

using System.Linq;

public static class ArraysInversion
{
    public static int[] InvertValues(int[] input)
    {
        return input.Select(x => -x).ToArray();
    }
}

Calculate Average

using System.Linq;

class AverageSolution
{
    public static double FindAverage(double[] array)
    {
        return array.Length == 0 ? 0 : array.Average();
    }
}

Highest and Lowest

Given a string like "4 3 5 -19 23 13 22", return a string with the highest and lowest values in in, e.g. "23 -19"

using System;                 // needed for String
using System.Linq;
public static class Kata
{
    public static string HighAndLow(string numbers)
    {
        return String.Format("{0} {1}",
            numbers.Split(' ').Max(x => int.Parse(x)),
            numbers.Split(' ').Min(x => int.Parse(x))
        );
    }
}

Friend or Foe

Return an array of names that are 4 chars long. Do not change the order from the input array.

using System.Linq;
using System.Collections.Generic;

public static class Kata {
    public static IEnumerable<string> FriendOrFoe (string[] names) {
        return names.Where(name => name.Length==4);
    }
}