Sha256: 09e0fdc7f413a587a040e60e3a03afe508273b3de4e66c1ec813426839158adb
Contents?: true
Size: 1.18 KB
Versions: 396
Compression:
Stored size: 1.18 KB
Contents
Public Class Anagram Private baseWord As String Public Sub New(baseWord As String) Me.baseWord = baseWord End Sub Public Function Match(potentialMatches As String()) As String() Dim matches As New List(Of String)() For Each word As String In potentialMatches If IsWordAnagramOfBaseWord(word) Then matches.Add(word) End If Next Return matches.OrderBy(Function(word) word).ToArray() End Function Private Function IsWordAnagramOfBaseWord(word As String) As Boolean Return (IsNotTheSameWordAsBaseWord(word) AndAlso HasSameLettersAsBaseWord(word)) End Function Private Function IsNotTheSameWordAsBaseWord(word As String) As Boolean Return Not baseWord.Equals(word, StringComparison.OrdinalIgnoreCase) End Function Private Function HasSameLettersAsBaseWord(word As String) As Boolean Return SortedCharArrayForString(baseWord).Equals(SortedCharArrayForString(word)) End Function Private Function SortedCharArrayForString(word As String) As String Return String.Concat(word.ToLower().OrderBy(Function(letter) letter)) End Function End Class
Version data entries
396 entries across 396 versions & 1 rubygems