-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdna-pairing.js
More file actions
37 lines (30 loc) · 733 Bytes
/
dna-pairing.js
File metadata and controls
37 lines (30 loc) · 733 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
33
34
35
36
37
/**
The DNA strand is missing the pairing element. Take each character, get its pair,
and return the results as a 2d array.
Base pairs are a pair of AT and CG. Match the missing element to the provided character.
Return the provided character as the first element in each array.
*/
const search = (char, pairs) => {
switch (char) {
case "T":
pairs.push(["T", "A"]);
break;
case "A":
pairs.push(["A", "T"]);
break;
case "C":
pairs.push(["C", "G"]);
break;
case "G":
pairs.push(["G", "C"]);
break;
}
};
function pairElement(str) {
var pairs = [];
for (let i = 0; i < str.length; i++) {
search(str[i], pairs);
}
return pairs;
}
pairElement("GCG");