DNA pairing
pair element
by trentHarlem
HTML
<h1>
DNA Pairing
</h1>
<p>
The DNA strand is missing the pairing element.<br> Take each character, get its pair, and return the results as a 2d array.
</p>
<p>
Base pairs are a pair of AT and CG. <br>
Match the missing element to the provided character.
</p>
<p>
For example, for the input GCG, return [["G", "C"], ["C","G"], ["G", "C"]]
</p>
<p>
The character and its pair are paired up in an array, and all the arrays are grouped into one encapsulating array.
</p>
JavaScript
const pairElement=(str) =>str.split('').map(el =>(el == 'G')?['G', 'C']:(el == 'C')?["C", "G"]:(el == 'T')?['T', 'A']:["A", "T"])
/* function pairElement(str) {
//let strArr = str.split('')
return str.split('').map(el => {
if (el == 'G') {
return ['G', 'C']
} else if (el == 'C') {
return ["C", "G"]
} else if (el == 'T') {
return ['T', 'A']
} else {
return ["A", "T"]
}
});
} */
console.log(pairElement("GCG"))
console.log(pairElement("CGC"))
console.log(pairElement("TGCA"))
/* console.log(pairElement("ATCGA")) */