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