Sha256: 06e89ea42986d3cebdc8ca4a2295aa566859b30dda52d1c326aba93e668c5624

Contents?: true

Size: 941 Bytes

Versions: 188

Compression:

Stored size: 941 Bytes

Contents

struct WordCount {

    func splitStringToArray(_ inString: String) -> [String] {
        return inString.characters.split(whereSeparator: { splitAt($0) }).map { String($0) }
    }

    func splitAt(_ characterToCompare: Character, charToSplitAt: String = " !&$%^&,:") -> Bool {
        for each in charToSplitAt.characters where each == characterToCompare {
            return true
        }
        return false
    }

    let words: String

    init(words: String) {
        self.words = words
    }

    func count() -> [String: Int] {
        var dict = [String: Int]()
        let cleanArray = splitStringToArray(words)

        cleanArray.forEach { string in
            if !string.isEmpty {
                if let count = dict[string.lowercased()] {
                    dict[string.lowercased()] = count + 1
                } else { dict[string.lowercased()] = 1
                }
            }
        }
        return dict
    }
}

Version data entries

188 entries across 188 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/swift/exercises/word-count/Sources/WordCountExample.swift
trackler-2.2.1.179 tracks/swift/exercises/word-count/Sources/WordCountExample.swift
trackler-2.2.1.178 tracks/swift/exercises/word-count/Sources/WordCountExample.swift
trackler-2.2.1.177 tracks/swift/exercises/word-count/Sources/WordCountExample.swift
trackler-2.2.1.176 tracks/swift/exercises/word-count/Sources/WordCountExample.swift
trackler-2.2.1.175 tracks/swift/exercises/word-count/Sources/WordCountExample.swift
trackler-2.2.1.174 tracks/swift/exercises/word-count/Sources/WordCountExample.swift
trackler-2.2.1.173 tracks/swift/exercises/word-count/Sources/WordCountExample.swift
trackler-2.2.1.172 tracks/swift/exercises/word-count/Sources/WordCountExample.swift
trackler-2.2.1.171 tracks/swift/exercises/word-count/Sources/WordCountExample.swift
trackler-2.2.1.170 tracks/swift/exercises/word-count/Sources/WordCountExample.swift
trackler-2.2.1.169 tracks/swift/exercises/word-count/Sources/WordCountExample.swift
trackler-2.2.1.167 tracks/swift/exercises/word-count/Sources/WordCountExample.swift
trackler-2.2.1.166 tracks/swift/exercises/word-count/Sources/WordCountExample.swift
trackler-2.2.1.165 tracks/swift/exercises/word-count/Sources/WordCountExample.swift
trackler-2.2.1.164 tracks/swift/exercises/word-count/Sources/WordCountExample.swift
trackler-2.2.1.163 tracks/swift/exercises/word-count/Sources/WordCountExample.swift
trackler-2.2.1.162 tracks/swift/exercises/word-count/Sources/WordCountExample.swift
trackler-2.2.1.161 tracks/swift/exercises/word-count/Sources/WordCountExample.swift
trackler-2.2.1.160 tracks/swift/exercises/word-count/Sources/WordCountExample.swift