function dnaStrand(dna){
const compl = dna;
dna.includes("A") && compl.replace(/A/g, "T");
dna.includes("T") && compl.replace(/T/g, "A")
dna.includes("C") && compl.replace(/C/g, "G")
dna.includes("G") && compl.replace(/G/g, "C")
console.log(compl)
return compl
}
I intend to form the complementary dna strand, that is, A is complementary to T and C is complemantary to G.
input >>> output ATGC >>>> TACG
String.replacedoes not modify the original string (why? BecauseStringis immutable).You can try to remap the values, something like:
String.replacecan be used this way: