Sha256: cef6ca9ded099606c89251424aeec6d912f8bf99534c78c5663508f57e74706b

Contents?: true

Size: 881 Bytes

Versions: 118

Compression:

Stored size: 881 Bytes

Contents

enum Nucleobase: Character {
    case adenine = "A",
    cytosine = "C",
    thymine = "T",
    guanine = "G"
}

struct DNA {

    var nucleotideCounts: [Nucleobase: Int] = [ .adenine: 0, .thymine: 0, .cytosine: 0, .guanine: 0 ]

    init?(strand: String) {
        let enumarated = strand.characters.enumerated()

        for (_, value) in enumarated {
            if let possibleNucleobase = Nucleobase(rawValue: value) {
                nucleotideCounts[possibleNucleobase]! += 1
            } else {
                return nil
            }
        }
    }

    func count(_ value: Character) -> Int {
        return nucleotideCounts[Nucleobase(rawValue: value)!]!
    }

    func counts() -> [String: Int] {
        var nCounts: [String: Int] = [:]
        for (k, v) in nucleotideCounts {
            nCounts[String(k.rawValue)] = v
        }
        return nCounts
    }

}

Version data entries

118 entries across 118 versions & 1 rubygems

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