Skip to content

Instantly share code, notes, and snippets.

@nickihastings
Created March 20, 2018 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickihastings/f8114d4edbd5ea96b3b7bfa0330565fe to your computer and use it in GitHub Desktop.
Save nickihastings/f8114d4edbd5ea96b3b7bfa0330565fe to your computer and use it in GitHub Desktop.
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