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

Version Path
trackler-2.2.1.180 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.179 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.178 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.177 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.176 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.175 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.174 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.173 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.172 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.171 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.170 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.169 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.167 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.166 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.165 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.164 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.163 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.162 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.161 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.160 tracks/vbnet/exercises/anagram/Example.vb