DNA Pairing - clumsy I know, but what's wrong when it does as asked?

Tell us what’s happening:

Your code so far

function pairElement(str) {
  var arr = str.split('');
  var newArr = [];
  var interArr = [];
  
  for (var i = 0; i < arr.length; i++) {
   switch (arr[i]) {
    case 'A':
        interArr.push("A,T");
        break;
    case 'T':
        interArr.push("T,A");
        break;
    case 'C':
        interArr.push("C,G");
        break;
    case 'G':
        interArr.push("G,C");
        break;
  }
    
  }
  newArr.push(interArr);
  return newArr;
}

pairElement("CTCTA");

Your browser information:

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

Link to the challenge:
https://www.freecodecamp.org/challenges/dna-pairing

Does almost what is asked.

You code returns
[β€œC,G”, β€œT,A”, β€œC,G”, β€œT,A”, β€œA,T”]
but this is what is expected
[[β€œC”,β€œG”],[β€œT”,β€œA”],[β€œC”,β€œG”],[β€œT”,β€œA”],[β€œA”,β€œT”]]

1 Like

Hi, thanks - so it does - I’m clearly an idiot. Back to the drawing board!

You should push [β€œC”,β€œG”]

1 Like

Thanks JohnBackUP - I will do so :slight_smile:
function pairElement(str) {
var arr = str.split(’’);
var newArr = [];

for (var i = 0; i < arr.length; i++) {
switch (arr[i]) {
case β€˜A’:
newArr.push([β€œA”,β€œT”]);
break;
case β€˜T’:
newArr.push([β€œT”,β€œA”]);
break;
case β€˜C’:
newArr.push([β€œC”,β€œG”]);
break;
case β€˜G’:
newArr.push([β€œG”,β€œC”]);
break;
}

}

return newArr;
}

pairElement(β€œGCG”);

You’re not and idiot! Another set of eyes is a great tool no matter what your doing.

Did it work ?

(the code)

Aww thank you alhazen1 :slight_smile:

It did John-freeCodeCamp :slight_smile:

1 Like