function pairElement(str) {
var array = str.split(“”)
var array2D = array.map((single) =>
single
.replace(/A/,“A,T”)
.replace(/T/,“T,A”)
.replace(/C/,“C,G”)
.replace(/G/,“G,C”)
.split()
);
console.log(str)
console.log(array)
return array2D;
}
console.log(pairElement(“ATCG”));
console shows:
ATCG
[ ‘A’, ‘T’, ‘C’, ‘G’ ]
[ [ ‘A,T,A’ ], [ ‘T,A’ ], [ ‘C,G,C’ ], [ ‘G,C’ ] ]
I would like to have the 2D array show only 2 letters per inner array. My syntax is the same why are some arrays containing 2 while others contain three?