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
2
Answers
String.replace
does not modify the original string (why? BecauseString
is immutable).You can try to remap the values, something like:
Issue is you are using replace and strings are imutable in JS so the interpreteur is not modifying the string but rather raturning a new modifyed string
also in your example you have a logical issue in your replacements: once you replace ‘A’ with ‘T’, if you immediately replace ‘T’ with ‘A’, it will revert the first replacement.
Here is how you can achieve desired results using a map: