This challenge is DNA pairing challenge in freecodecamp. The goal is to return the missing strand pair into 2d array (return the provided character as the first element in each array). Freecodecamp provided the base pairing AT and CG information in wikipedia base pair.

Here is the example DNA pairing which works with our challenge :

  • If I have G element then we return an array [”G”, “C”]
  • If I have C element then we return an array [“C”, “G”]
  • If I have A element then we return an array [“A”, “T”]
  • If I have T element then we return an array [“T”, “A”]
  • For example we have CGC in the first element then we have to return [[“C”, “G”], [“G”, “C”], [“C”, “G”]]

I will start code with the switch case, i have a good reference from Mozilla Developer Network and here is the steps :

  • Create an empty array for store the paired array (result)
var res = []
  • I make one more variable with callback function
var getPaired = function(char){
case 'A':
res.push(["A", "T"]);
case 'T':
res.push(["T", "A"]);
case 'G':
res.push(["G", "C"]);
case 'C':
res.push(["C", "G"]);

  • Make a loop through the str then set value from the getPaired
for(var i = 0; i < str.length; i++){
  • finally return the getPaired variable
return getPaired();

Here is the full code from my codepen :