ðŸŽ‰ Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io ðŸŽ‰

# Nytelife26's solution

## to RNA Transcription in the Vim script Track

Published at Feb 05 2021 · 0 comments
Instructions
Test suite
Solution

Given a DNA strand, return its RNA complement (per RNA transcription).

Both DNA and RNA strands are a sequence of nucleotides.

The four nucleotides found in DNA are adenine (A), cytosine (C), guanine (G) and thymine (T).

The four nucleotides found in RNA are adenine (A), cytosine (C), guanine (G) and uracil (U).

Given a DNA strand, its transcribed RNA strand is formed by replacing each nucleotide with its complement:

• `G` -> `C`
• `C` -> `G`
• `T` -> `A`
• `A` -> `U`

# How to run the tests

If you don't know how to run Vader tests, see: Tests.

For general information about the Vim script track, see: Help.

## Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

``````"
" Version: 1.0.1
"

Before:
unlet! input expected

Execute (RNA complement of cytosine is guanine):
let input = "C"
let expected = "G"
AssertEqual expected, ToRna(input)

Execute (RNA complement of guanine is cytosine):
let input = "G"
let expected = "C"
AssertEqual expected, ToRna(input)

Execute (RNA complement of thymine is adenine):
let input = "T"
let expected = "A"
AssertEqual expected, ToRna(input)

Execute (RNA complement of adenine is uracil):
let input = "A"
let expected = "U"
AssertEqual expected, ToRna(input)

Execute (RNA complement):
let input = "ACGTGGTCTTAA"
let expected = "UGCACCAGAAUU"
AssertEqual expected, ToRna(input)

Execute (correctly handles invalid input (RNA instead of DNA)):
let input = "U"
let expected = ''
AssertEqual expected, ToRna(input)

Execute (correctly handles completely invalid DNA input):
let input = "XXX"
let expected = ''
AssertEqual expected, ToRna(input)

Execute (correctly handles partially invalid DNA input):
let input = "ACGTXXXCTTAA"
let expected = ''
AssertEqual expected, ToRna(input)``````
``````function! ToRna(strand) abort
let strand = toupper(a:strand)
if strand !~ '^[ACGT]*\$'
return ''
endif
let new = ''
for char in split(strand, '\zs')
if char == 'A'
let new .= 'U'
elseif char == 'C'
let new .= 'G'
elseif char == 'G'
let new .= 'C'
elseif char == 'T'
let new .= 'A'
endif
endfor
return new
endfunction``````

### What can you learn from this solution?

A huge amount can be learned from reading other peopleâ€™s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

• What compromises have been made?