Map function

Transcrição de RNA
Transcrição de RNA em Go
// Package strand is a small library for returning the RNA complement of a DNA strand.
package rnatranscription

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.

23 de setembro de 2026 · Achou útil?