알고리즘 19 - Complementary DNA

박진현·2021년 7월 15일
0

Q.

Deoxyribonucleic acid (DNA) is a chemical found in the nucleus of cells and carries the "instructions" for the development and functioning of living organisms.

If you want to know more: http://en.wikipedia.org/wiki/DNA

In DNA strings, symbols "A" and "T" are complements of each other, as "C" and "G". You have function with one side of the DNA (string, except for Haskell); you need to get the other complementary side. DNA strand is never empty or there is no DNA at all (again, except for Haskell).

More similar exercise are found here: http://rosalind.info/problems/list-view/ (source)

Example: (input: output)

DNAStrand ("ATTGC") // return "TAACG"
DNAStrand ("GTAT") // return "CATA"

A)

function DNAStrand(dna){
  //your code here
  let result = ''
  for(i=0;i<dna.length;i++) {
    if(dna[i] === 'A'){
      result+= 'T'
    }
    else if (dna[i] === 'T'){
      result+='A'
    }
    else if (dna[i] === 'G') {
      result+= 'C'
    }
    else if (dna[i] === 'C') {
      result += 'G'
    }
  }
  return result
}
profile
👨🏻‍💻 호기심이 많고 에러를 좋아하는 프론트엔드 개발자 박진현 입니다.

0개의 댓글