Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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. For example, for the input GCG, return [["G", "C"], ["C","G"],["G", "C"]…
function pairElement(str) {
str = str.split("");
var pairs = [];
for(var i = 0; i < str.length; i++){
switch (str[i]) {
case "C":
pairs.push(["C", "G"]);
break;
case "G":
pairs.push(["G", "C"]);
break;
case "A":
pairs.push(["A","T"]);
break;
case "T":
pairs.push(["T", "A"]);
break;
}
}
return pairs;
}
pairElement("GCG");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment