I'm trying to get the console.log output at the bottom of the sample code. Currently, my code is returning undefined. I would like to know which part I did wrong.
I would also like to know if there are other, more efficient approaches in solving the problem.
function pairElement(str) {
return str.split('')
.forEach(function(element){
return element.split('').map(function(pair){
if (pair == "G") {return ["G","C"];}
else if (pair == "C") {return ["C","G"];}
else if (pair == "T") {return ["T","A"];}
else {return ["A","T"];}
});
});
}
console.log(pairElement("ATCG"));
// -> Should be [["A","T"], ["T","A"], ["C","G"], ["G","C"]]
// -> But currently, it is returning undefined