-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplementaryDNA.js
More file actions
32 lines (21 loc) · 894 Bytes
/
complementaryDNA.js
File metadata and controls
32 lines (21 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Deoxyribonucleic acid (DNA) is a chemical found in the nucleus of cells and carries the "instructions" for the development and functioning of living organisms.
// In DNA strings, symbols "A" and "T" are complements of each other, as "C" and "G".
// Your function receives one side of the DNA (string, except for Haskell); you need to return the other complementary side.
// DNA strand is never empty or there is no DNA at all (again, except for Haskell).
// Example: (input --> output)
// "ATTGC" --> "TAACG"
// "GTAT" --> "CATA"
function DNAStrand(dna){
return dna.split('')
.map( el => {
if (el == 'A') return 'T';
if (el == 'T') return 'A';
if (el == 'C') return 'G';
if (el == 'G') return 'C';
}).join('')
}
// OR
var pairs = {'A':'T','T':'A','C':'G','G':'C'};
function DNAStrand(dna){
return dna.split('').map(v => pairs[v]).join('');
}