Sha256: 75d39035d92aaa1a6bfab2db1d5f1347de0ad4b10ec273ced510f7ef6f608218

Contents?: true

Size: 708 Bytes

Versions: 118

Compression:

Stored size: 708 Bytes

Contents

enum TranscriptionError: Error {
    case invalidNucleotide
}

struct Nucleotide {
    func complementOfDNA() throws -> String {
        return try transcribe(dnaToRna)
    }

    private let value: String

    init(_ nucleotide: String) {
        self.value = nucleotide
    }

    private let dnaToRna: [Character: String] = [ "G": "C", "C": "G", "T": "A", "A": "U" ]

    private func transcribe(_ dict: [Character: String]) throws -> String {
        var tempText = ""
        for each in self.value.characters {
            if dict[each] == nil {
                throw TranscriptionError.invalidNucleotide
            }
            tempText += dict[each] ?? ""
        }
        return tempText
    }
}

Version data entries

118 entries across 118 versions & 1 rubygems

Version Path
trackler-2.2.1.159 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.158 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.157 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.156 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.155 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.154 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.153 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.152 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.151 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.150 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.149 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.148 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.147 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.146 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.145 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.144 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.143 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.142 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.141 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.140 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift