Hey everyone! I would like some of you more experienced programmers to critique my solution to this problem. After my code passed all the tests, I compared it to the solutions on the “Get a Hint” page and realized it was quite different. I was wondering if there is a reason that the solutions given used the switch
method instead of what I did. I’m still a newbie so I’m trying to learn best practices, how to write clean code, etc. Thanks
Your code so far
function pairElement(str) {
let newArr = [];
for (let i = 0; i < str.length; i++) {
if (str[i] === "G") {
newArr.push(["G", "C"]);
} else if (str[i] === "C") {
newArr.push(["C", "G"]);
} else if (str[i] === "T") {
newArr.push(["T", "A"]);
} else {
newArr.push(["A", "T"]);
}
}
return newArr;
}
console.log(pairElement("GCG"));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36
Challenge Information:
Intermediate Algorithm Scripting - DNA Pairing