Ad
  • Improve performance
  • Refactor tests
  • Refactor method signature
  • Add documentation
Code
Diff
  • using System.Linq;
    
    public static class Palindrome
    {
      public static bool IsPalindrome(this string word)
      {
        // Normalize the input
        var upper = word.ToUpperInvariant();
        
        // For every chatacter in the first half..
        for (var i = 0; i < upper.Length / 2; ++i)
          // if the char doesn't match the one in the second half..
          if (upper[i] != upper[upper.Length - i - 1])
            // the word is not a palindrome
            return false;
    
        // The word is not a palindrome
        return true;
      }
    }
    • using System.Linq;
    • class Palindrome
    • public static class Palindrome
    • {
    • public static bool Check(string word) {
    • public static bool IsPalindrome(this string word)
    • {
    • // Normalize the input
    • var upper = word.ToUpperInvariant();
    • return upper.SequenceEqual(upper.Reverse());
    • // For every chatacter in the first half..
    • for (var i = 0; i < upper.Length / 2; ++i)
    • // if the char doesn't match the one in the second half..
    • if (upper[i] != upper[upper.Length - i - 1])
    • // the word is not a palindrome
    • return false;
    • // The word is not a palindrome
    • return true;
    • }
    • }
Fundamentals
Numbers
Data Types
Integers
  • Refactor to expression and extension method
  • Add documentation
  • Refactor tests
Code
Diff
  • public static class Kata
    {
        /// <summary>
        /// Validates if the given <paramref name="input"/> is an odd number
        /// </summary>
        /// <param name="input">Number to validate</param>
        /// <returns>True if the <paramref name="input"/> is an odd number</returns>
        public static bool IsOdd(this int input)
            => (input & 1) == 1;
    }
    • public static class Kata
    • {
    • public static bool IsOdd(int input)
    • {
    • return (input & 1) == 1;
    • }
    • /// <summary>
    • /// Validates if the given <paramref name="input"/> is an odd number
    • /// </summary>
    • /// <param name="input">Number to validate</param>
    • /// <returns>True if the <paramref name="input"/> is an odd number</returns>
    • public static bool IsOdd(this int input)
    • => (input & 1) == 1;
    • }