i need swap letters in string (dna strand) using ruby , following rules:
'a'replaced't''t'replaced'a''c'replaced'g''g'replaced'c'
for example, 'acgta' should become 'tgcat'.
i have got far:
def dna_strand(dna) dna.tr!('a', 't') end
you quite close:
dna.tr('atcg', 'tagc') # => "tgcat" see ruby-doc.org on tr:
returns copy of
strcharacters infrom_strreplaced corresponding characters into_str.
use tr! same way if want modify string in-place.
Comments
Post a Comment