Intermediate Algorithm Scripting - DNA Pairing

As beginner i was happy i did this without looking for hints, then i checked to see how my answer compared to solutions and i was left with to say. I tried the switch though but couldn’t make out the syntax. the end justifies the means, ryt :stuck_out_tongue_closed_eyes:

function pairElement(str) {
  let pair1 = "AT"
  let pair2 = "CG"
  const dna = [];
  for (let i = 0; i < str.length; i++) {
    const basePair = [];
    if (pair1.indexOf(str[i]) === -1) {
      if(str[i] === pair2[0]){
        basePair.push(pair2[0]);
        basePair.push(pair2[1]);
      } else {
        basePair.push(pair2[1]);
        basePair.push(pair2[0]);
      }
      dna.push(basePair);
    } else if (str[i] === pair1[0]){
      basePair.push(pair1[0]);
      basePair.push(pair1[1]);
      dna.push(basePair);
    } else {
      basePair.push(pair1[1]);
      basePair.push(pair1[0]);
      dna.push(basePair);
    }
  }
  return dna
}

pairElement("GCG");
pairElement("TTGAG")

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36

Challenge: Intermediate Algorithm Scripting - DNA Pairing

Link to the challenge:

hi, I’m not sure if you had a question about this? (I couldn’t detect it)
If not, what is the purpose of posting your code?