Skip to content

Instantly share code, notes, and snippets.

@rfprod
Last active April 22, 2017 16:00
Show Gist options
  • Save rfprod/0777154418c2e8a5039b to your computer and use it in GitHub Desktop.
Save rfprod/0777154418c2e8a5039b to your computer and use it in GitHub Desktop.
DNA Pairing
function pair(str) {
var basePair1 = "AT";
var basePair2 = "CG";
var inputArr = str.split("");
var tmpArr = [];
var outputArr = [];
for (var i=0;i<inputArr.length;i++){
tmpArr.push(inputArr[i]);
if ((inputArr[i].indexOf(basePair1[0])>-1)||(inputArr[i].indexOf(basePair1[1])>-1)){
for (var j=0;j<basePair1.length;j++){
if (basePair1[j] != inputArr[i]){
tmpArr.push(basePair1[j]);
}
}
}
if ((inputArr[i].indexOf(basePair2[0])>-1)||(inputArr[i].indexOf(basePair2[1])>-1)){
for (var k=0;k<basePair2.length;k++){
if (basePair2[k] != inputArr[i]){
tmpArr.push(basePair2[k]);
}
}
}
outputArr.push(tmpArr);
tmpArr = [];
}
return outputArr;
}
pair("GCG");

DNA Pairing

The DNA strand is missing the pairing element. Each character gets its pair, and returns to the results as a 2d array. Base pairs are a pair of AT and CG. For example, for the input GCG, return [["G", "C"], ["C","G"],["G", "C"]] The character and its pair are paired up in an array, and all the arrays are grouped into one encapsulating array.

A script by V.

License.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment