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