What’s wrong with my code, anybody can help me with this? Do I need a break after every push method?
Question:
DNA Pairing
The DNA strand is missing the pairing element. Take each character, get its pair, and return the results as a 2d array.
Base pairs are a pair of AT and CG. Match the missing element to the provided character.
Return the provided character as the first element in each array.
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.
Your code so far
function pairElement(str) {
const newStr = [];
for (let i = 0; i < str.length; i++) {
if (str[i] === "A") {
newStr.push(["A", "T"])
} else if (str[i] === "T") {
newStr.push(["T", "A"])
} else if (str[i] === "G") {
newStr.push(["G", "C"])
}
return newStr.push(["C", "G"])
}
return newStr;
}
pairElement("GCG");
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36
Challenge: DNA Pairing
Link to the challenge: