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.18 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.17 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.16 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.15 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.14 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.13 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.12 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.11 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.10 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.9 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.8 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.7 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.6 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.5 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.4 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.3 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.2 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.1 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.1.0 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.2.0.6 tracks/swift/exercises/anagram/Sources/AnagramExample.swift