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