Sha256: e9ba0bf2ff528aabc58a193105e5e38054f9404412f30448791c37b0257d1866

Contents?: true

Size: 1.13 KB

Versions: 208

Compression:

Stored size: 1.13 KB

Contents

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

public class Anagram
{
    private string baseWord;

    public Anagram (string baseWord)
    {
        this.baseWord = baseWord;
    }

    public string[] Match (string[] potentialMatches)
    {
        List<string> matches = new List<string>();

        foreach (string word in potentialMatches)
        {
            if (IsWordAnagramOfBaseWord(word))
            {
                matches.Add(word);
            }
        }

        return matches.OrderBy(word => word).ToArray();
    }

    private bool IsWordAnagramOfBaseWord (string word)
    {
        return (IsNotTheSameWordAsBaseWord(word) && HasSameLettersAsBaseWord(word));
    }

    private bool IsNotTheSameWordAsBaseWord (string word)
    {
        return ! baseWord.Equals(word,StringComparison.OrdinalIgnoreCase);
    }

    private bool HasSameLettersAsBaseWord (string word)
    {
        return SortedCharArrayForString(baseWord).Equals(SortedCharArrayForString(word));
    }

    private string SortedCharArrayForString (string word)
    {
        return String.Concat(word.ToLower().OrderBy(letter => letter));
    }
}

Version data entries

208 entries across 208 versions & 1 rubygems

Version Path
trackler-2.1.0.12 tracks/csharp/exercises/anagram/Example.cs
trackler-2.1.0.11 tracks/csharp/exercises/anagram/Example.cs
trackler-2.1.0.10 tracks/csharp/exercises/anagram/Example.cs
trackler-2.1.0.9 tracks/csharp/exercises/anagram/Example.cs
trackler-2.1.0.8 tracks/csharp/exercises/anagram/Example.cs
trackler-2.1.0.7 tracks/csharp/exercises/anagram/Example.cs
trackler-2.1.0.6 tracks/csharp/exercises/anagram/Example.cs
trackler-2.1.0.5 tracks/csharp/exercises/anagram/Example.cs
trackler-2.1.0.4 tracks/csharp/exercises/anagram/Example.cs
trackler-2.1.0.3 tracks/csharp/exercises/anagram/Example.cs
trackler-2.1.0.2 tracks/csharp/exercises/anagram/Example.cs
trackler-2.1.0.1 tracks/csharp/exercises/anagram/Example.cs
trackler-2.1.0.0 tracks/csharp/exercises/anagram/Example.cs
trackler-2.0.8.55 tracks/csharp/exercises/anagram/Example.cs
trackler-2.0.8.54 tracks/csharp/exercises/anagram/Example.cs
trackler-2.0.8.53 tracks/csharp/exercises/anagram/Example.cs
trackler-2.0.8.52 tracks/csharp/exercises/anagram/Example.cs
trackler-2.0.8.51 tracks/csharp/exercises/anagram/Example.cs
trackler-2.0.8.50 tracks/csharp/exercises/anagram/Example.cs
trackler-2.0.8.49 tracks/csharp/exercises/anagram/Example.cs