DEV Community

Oscar Hernandez
Oscar Hernandez

Posted on

1 1

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"]].
/

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (2)

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay