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.180 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.179 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.178 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.177 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.176 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.175 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.174 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.173 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.172 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.171 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.170 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.169 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.167 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.166 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.165 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.164 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.163 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.162 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.161 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift
trackler-2.2.1.160 tracks/swift/exercises/rna-transcription/Sources/RnaTranscriptionExample.swift