Sha256: 4e3d9f8795b698625716e291a8e53697ff4dabd2746501db0b3b515086c3462e

Contents?: true

Size: 659 Bytes

Versions: 208

Compression:

Stored size: 659 Bytes

Contents

struct Hamming {
    static func compute(_ input: String, against: String) -> Int? {
        var differences = 0

        let char1 = convertStringToArray(input)
        let char2 = convertStringToArray(against)

        if char1.count != char2.count { return nil }
        for i in 0..<char1.count {
            if char1[i] != char2[i] {
                differences += 1
            }
        }
        return differences
    }

}

private func convertStringToArray(_ input: String) -> [Character] {
    var characterArray: [Character] = []

    for character in input.characters {
        characterArray.append(character)
    }

    return characterArray
}

Version data entries

208 entries across 208 versions & 1 rubygems

Version Path
trackler-1.0.3.0 tracks/swift/exercises/hamming/HammingExample.swift
trackler-1.0.2.1 tracks/swift/exercises/hamming/HammingExample.swift
trackler-1.0.2.0 tracks/swift/exercises/hamming/HammingExample.swift
trackler-1.0.1.2 tracks/swift/exercises/hamming/HammingExample.swift
trackler-1.0.1.1 tracks/swift/exercises/hamming/HammingExample.swift
trackler-1.0.1.0 tracks/swift/exercises/hamming/HammingExample.swift
trackler-1.0.0.1 tracks/swift/exercises/hamming/HammingExample.swift
trackler-1.0.0 tracks/swift/exercises/hamming/HammingExample.swift