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.1.0.41 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.1.0.40 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.1.0.39 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.1.0.38 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.1.0.37 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.1.0.36 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.1.0.34 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.1.0.33 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.1.0.32 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.1.0.31 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.1.0.30 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.1.0.29 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.1.0.28 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.1.0.27 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.1.0.26 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.1.0.25 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.1.0.24 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.1.0.23 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.1.0.22 tracks/swift/exercises/anagram/Sources/AnagramExample.swift
trackler-2.1.0.21 tracks/swift/exercises/anagram/Sources/AnagramExample.swift