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.159 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.158 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.157 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.156 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.155 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.154 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.153 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.152 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.151 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.150 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.149 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.148 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.147 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.146 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.145 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.144 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.143 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.142 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.141 tracks/vbnet/exercises/anagram/Example.vb
trackler-2.2.1.140 tracks/vbnet/exercises/anagram/Example.vb