I’m trying to solve this JavaScript challenge (DNA Pairing) and my algorithm returns a similar array, the only difference is that mine returns some spaces and multiple lines.
This is what my algorithm returns:
[ [ ‘A’, ‘T’ ],
[ ‘T’, ‘A’ ],
[ ‘C’, ‘G’ ],
[ ‘G’, ‘C’ ],
[ ‘A’, ‘T’ ] ]
And this is what it should returns according to the challenge:
[[“A”,“T”],[“T”,“A”],[“C”,“G”],[“G”,“C”],[“A”,“T”]]
Thanks in advance!
function pairElement(str) {
let newArr = [];
for (let i = 0; i < str.length; i++) {
switch (str[i]) {
case 'C':
newArr.push([str[i], 'G']);
break;
case 'G':
newArr.push([str[i], 'C']);
break;
case 'A':
newArr.push([str[i], 'T']);
break;
case 'T':
newArr.push([str[i], 'A']);
break;
}
}
console.log(newArr);
return str;
}
pairElement("ATCGA");
Challenge: DNA Pairing
Link to the challenge: