Intermediate Algorithm Scripting: DNA Pairing - advice?

Tell us what’s happening:

Hi there, I believe this solution is correct. I checked that on the console and it works fine. It does not seem to satisfy fCC though.

Any advice?

Thanks,
Tower

Your code so far


function pairElement(str) {

const pairsObj = {
  A: "T",
  T: "A",
  C: "G",
  G: "C"
}

let res = [];

for(let i = 0; i < str.length; i++) {
  res.push( [ [ str[i], pairsObj[str[i]] ] ] );  
}

return res;

}

pairElement("ATCGA");

Your browser information:

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

Challenge: DNA Pairing

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/dna-pairing

You are close, but you should only have a two-dimensional array for the above test example:

 [
   [ 'A', 'T' ] ,
   [ 'T', 'A'  ],
   [ 'C', 'G' ],
   [ 'G', 'C'  ],
   [ 'A', 'T' ]
 ]

Instead, you are returning a 3-dimensional array:

[
  [
    ['A', 'T']
  ],
  [
    ['T', 'A']
  ],
  [
    ['C', 'G']
  ],
  [
    ['G', 'C']
  ],
  [
    ['A', 'T']
  ]
]

You just have one extra set of [ and ] in your res.push argument.

1 Like

Read this question again you have to return 2d array but you returning 3d array.

1 Like

OMG - you are right. Not even sure why I randomly added those additional pairs of square brackets.
Thanks for your help.