link to Challenge : https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/dna-pairing
Can someone please explain me why my code is wrong ? I don´t understand it. The solution also works with the push method into an empty Array.
Thank you in advance!!!
…
// Convert str to Array
//
var emptyArray = [];
var a = ["A", "T"];
var c = ["C", "G"];
var g = ["G", "C"];
var t = ["T", "A"];
//emptyArray.push(g,a)
function pairElement(str) {
var splitArray = str.split("");
for(var i = 0; i < splitArray.length; i++) {
if(splitArray[i] == "A" ) {
emptyArray.push(a)
}
else if (splitArray[i] == "C") {
emptyArray.push(c)
}
else if (splitArray[i] == "G") {
emptyArray.push(g)
}
else if (splitArray[i] == "T") {
emptyArray.push(t)
}
}
return emptyArray
}
console.log(pairElement("CTCTA"));
…