Your opinion about my DNA pairing exercise

Hey guys, I have just completed the DNA pairing exercise.

I’m feeling good and surprised :grinning: since it didn’t take me too much time like the previous Intermediate challenges (the Wherefore art thou made me feel a little bit frustrated :sleepy:).

This was my approach:

function pairElement(str) {
  //1-Taking each character
  let arr = str.split('');
  let arr2D = [];

  //2-Getting its pair
  //console.log(arr[0])
  
  for(let i = 0; i < arr.length; i++){
    switch(arr[i]){
    case "A":
       arr2D.push(['A']);
      arr2D[i].push('T');
    break;

    case "T":
      arr2D.push(['T']);
      arr2D[i].push('A');
    break;

    case "C":
      arr2D.push(['C']);
      arr2D[i].push('G');
    break;
      
    case "G":
      arr2D.push(['G']);
      arr2D[i].push('C');
    break;
  }
  }
  //3-return results as 2D array
  return arr2D;
}
pairElement("ATCGA");

What are your thoughts?

Thank you in advance!

I edited your post to include spoiler tags, for those who have not worked on the challenge yet.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.