// Package strand is a small library for returning the RNA complement of a DNA strand.
package strand
import "strings"
// toRNA returns the RNA complement of the input DNA strand.
func ToRNA(dna string) string {
return strings.Map(func(r rune) rune {
switch r {
case 'G':
return 'C'
case 'C':
return 'G'
case 'T':
return 'A'
case 'A':
return 'U'
}
return r
}, dna)
}
This approach passes the input string
into the strings
Map()
function.
The function uses a switch
statement to translate the DNA character into an RNA character.
7th Aug 2024
·
Found it useful?