DEV Community

Oscar Hernandez
Oscar Hernandez

Posted on

DNA paring free code camp intermediate algorithm

function pairElement(str) {
var a = /[A-Z]/gi;
var b = []; var arr =[];
var x =[]; var args =[];
for(let i=0; i<str.length;i++){
b = str.match(a);
if(b[i] === "A"){
arr = b[i].concat("T");
}if(b[i] === "T"){
arr = b[i].concat("A");
}if(b[i] === "C"){
arr = b[i].concat("G");
}else if(b[i] === "G"){
arr = b[i].concat("C");
}
var x = arr.split("");
args.push(x)
console.log(args);

}

return args;
}
pairElement("TGCGAT");
/pairElement("ATCGA") should return [["A","T"],["T","A"],["C","G"],["G","C"],["A","T"]].
Passed
pairElement("TTGAG") should return [["T","A"],["T","A"],["G","C"],["A","T"],["G","C"]].
Passed
pairElement("CTCTA") should return [["C","G"],["T","A"],["C","G"],["T","A"],["A","T"]].
/

Top comments (2)

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
95freedom95 profile image
Oscar Hernandez