Sha256: fdc51a4183d30470ce05a3c759207ef679cef32857c8d88b9a9502108ade5b2f

Contents?: true

Size: 879 Bytes

Versions: 207

Compression:

Stored size: 879 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

207 entries across 207 versions & 1 rubygems

Version Path
trackler-2.2.1.60 tracks/swift/exercises/nucleotide-count/Sources/NucleotideCountExample.swift
trackler-2.2.1.59 tracks/swift/exercises/nucleotide-count/Sources/NucleotideCountExample.swift
trackler-2.2.1.58 tracks/swift/exercises/nucleotide-count/Sources/NucleotideCountExample.swift
trackler-2.2.1.57 tracks/swift/exercises/nucleotide-count/Sources/NucleotideCountExample.swift
trackler-2.2.1.56 tracks/swift/exercises/nucleotide-count/Sources/NucleotideCountExample.swift
trackler-2.2.1.55 tracks/swift/exercises/nucleotide-count/Sources/NucleotideCountExample.swift
trackler-2.2.1.54 tracks/swift/exercises/nucleotide-count/Sources/NucleotideCountExample.swift
trackler-2.2.1.53 tracks/swift/exercises/nucleotide-count/Sources/NucleotideCountExample.swift
trackler-2.2.1.52 tracks/swift/exercises/nucleotide-count/Sources/NucleotideCountExample.swift
trackler-2.2.1.51 tracks/swift/exercises/nucleotide-count/Sources/NucleotideCountExample.swift
trackler-2.2.1.50 tracks/swift/exercises/nucleotide-count/Sources/NucleotideCountExample.swift
trackler-2.2.1.49 tracks/swift/exercises/nucleotide-count/Sources/NucleotideCountExample.swift
trackler-2.2.1.48 tracks/swift/exercises/nucleotide-count/Sources/NucleotideCountExample.swift
trackler-2.2.1.47 tracks/swift/exercises/nucleotide-count/Sources/NucleotideCountExample.swift
trackler-2.2.1.46 tracks/swift/exercises/nucleotide-count/Sources/NucleotideCountExample.swift
trackler-2.2.1.45 tracks/swift/exercises/nucleotide-count/Sources/NucleotideCountExample.swift
trackler-2.2.1.44 tracks/swift/exercises/nucleotide-count/Sources/NucleotideCountExample.swift
trackler-2.2.1.43 tracks/swift/exercises/nucleotide-count/Sources/NucleotideCountExample.swift
trackler-2.2.1.42 tracks/swift/exercises/nucleotide-count/Sources/NucleotideCountExample.swift
trackler-2.2.1.41 tracks/swift/exercises/nucleotide-count/Sources/NucleotideCountExample.swift