I created a solution to the DNA Pairing Challenge but I’m not sure why map
works here.
function pairElement(str) {
let paired = [];
str = str
.split("")
//how does map work here?
.map(letter => {
return letter == "A" ? paired.push(["A", "T"])
: letter == "T" ? paired.push(["T", "A"])
: letter == "G" ? paired.push(["G", "C"])
: letter == "C" ? paired.push(["C", "G"])
: letter;
});
return paired;
}
pairElement("GCG");
I’ve come to the conclusion that I’m basically using map
incorrectly and I should instead be using forEach
. Instead of returning an array the way map
is built, I’m forcing it to push a nested array to the paired variable.
Any thoughts or input would be appreciated.