I have a problem with this challenge, it seems to be correct because when I test it on the developer tool console it works but on FCC console doesn’t work, where do you think the problem is?
here is the code:
function pairElement(str) {
let toArr = str.split("");
let newArr = [];
for(let i = 0; i < str.length; i++){
if(toArr[i] === "C" || toArr[i] === "G"){
if(toArr[i] === "C"){
newArr.push(["CG"]);
}else{
newArr.push(["GC"]);
}
}
if(toArr[i] === "A" || toArr[i] === "T"){
if(toArr[i] === "A"){
newArr.push(["AT"]);
}else{
newArr.push(["TA"]);
}
}
}
return newArr;
}
pairElement("GCG");
If you click the Get A Hint button on the challenge, the Intermediate Solution provides a more concise solution. To be considered concise, you do not want to see “similar” code written through out the function. You have several newArr.push statements and several if statements which are similar in nature. Imagine if there were 100 more possible letter mappings how much more code you would have to write using your approach vs. the Intermediate Solution’s code. The only thing you would have to change in the Intermediate solution would be the pairs object.