Sha256: 0f7b831a45cc9523bfb16b13960cae161241054c21bf059cec2f665340a2a4a5

Contents?: true

Size: 768 Bytes

Versions: 396

Compression:

Stored size: 768 Bytes

Contents

struct Anagram {
    var baseWord = ""
    init (word: String) {
        baseWord = word
    }

    func sortLetters(_ wordToSort: String) -> String {
        var characters: [String] = []
        for char in wordToSort.characters {
            characters.append("\(char)")
        }
        characters = characters.sorted(by: < )
        return characters.reduce("", +)
    }

    func match(_ words: [String]) -> [String] {
        var matches: [String] = []

        for candidateWord in words {
            if sortLetters(baseWord.lowercased()) == sortLetters(candidateWord.lowercased())
                && baseWord.lowercased() != candidateWord.lowercased() {
                matches.append(candidateWord)
            }
        }

        return matches
    }

}

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.58 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.57 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.56 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.55 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.54 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.53 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.52 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.51 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.50 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.49 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.48 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.47 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.46 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.45 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.44 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.43 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.42 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.41 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.40 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.39 tracks/swift/exercises/anagram/Sources/AnagramExample.swift