DNA Pairing(help)

DNA Pairing(help)
0.0 0

#1

Hey, guys, can anyone help me out on this? I am not sure what I am I doing wrong as i cannot pass the tests.

var pair_1 = ["A","T"];
var pair_1_reverse = ["T","A"];
var pair_2 = ["C","G"];
var pair_2_reverse = ["G","C"];
var result = [];
function pairElement(str) {
  str = str.split("");
  var i ;
  for(i = 0;i < str.length;i++){
     if(str[i] === "A" ){
         result.push(pair_1);
     }
     else if(str[i] === "T"){
       result.push(pair_1_reverse);
     }
     else if(str[i] === "C"){
      result.push(pair_2);
    }
     else{
      result.push(pair_2_reverse);
    }
  }
  return result;
}

pairElement("CTCTA");

Thanks in advance for your help!


#2

Move this variable declaration inside the pairElement function. Because it is globally declared and the FCC tests make consecutive calls to the function, result does not get reset to an empty array at the start of each function call.


#3

Of course. Spot on! I will be on the lookout for mistakes like that.