DNA Pairing challenge - Why does my solution not work?

I’m trying to solve this JavaScript challenge (DNA Pairing) and my algorithm returns a similar array, the only difference is that mine returns some spaces and multiple lines.

This is what my algorithm returns:
[ [ ‘A’, ‘T’ ],
[ ‘T’, ‘A’ ],
[ ‘C’, ‘G’ ],
[ ‘G’, ‘C’ ],
[ ‘A’, ‘T’ ] ]

And this is what it should returns according to the challenge:
[[“A”,“T”],[“T”,“A”],[“C”,“G”],[“G”,“C”],[“A”,“T”]]

Thanks in advance!


function pairElement(str) {

let newArr = [];

for (let i = 0; i < str.length; i++) {
  switch (str[i]) {
    case 'C':
      newArr.push([str[i], 'G']);
      break;
    case 'G':
      newArr.push([str[i], 'C']);
      break;
    case 'A':
      newArr.push([str[i], 'T']);
      break;
    case 'T':
      newArr.push([str[i], 'A']);
      break;
  }
}
console.log(newArr);
return str;
}

pairElement("ATCGA");

Challenge: DNA Pairing

Link to the challenge:

I respond to myself. The solution is right but I had forgotten to return the correct variable: newArr :sweat_smile: :sweat_smile: :sweat_smile:

yeah , I spent like 10 min. and found that you were returning str , then I saw you found it already :joy:

1 Like

Sorry about that!! :sweat_smile:

I spent more than half an hour with this silly thing. I guess sometimes these things happen.

Thank you anyway!! :smiley: