Hey guys, I have just completed the DNA pairing exercise.
I’m feeling good and surprised since it didn’t take me too much time like the previous Intermediate challenges (the Wherefore art thou made me feel a little bit frustrated
).
This was my approach:
function pairElement(str) {
//1-Taking each character
let arr = str.split('');
let arr2D = [];
//2-Getting its pair
//console.log(arr[0])
for(let i = 0; i < arr.length; i++){
switch(arr[i]){
case "A":
arr2D.push(['A']);
arr2D[i].push('T');
break;
case "T":
arr2D.push(['T']);
arr2D[i].push('A');
break;
case "C":
arr2D.push(['C']);
arr2D[i].push('G');
break;
case "G":
arr2D.push(['G']);
arr2D[i].push('C');
break;
}
}
//3-return results as 2D array
return arr2D;
}
pairElement("ATCGA");
What are your thoughts?
Thank you in advance!