Created
October 10, 2017 16:28
-
-
Save jwill9999/dc8136488a672a1bbab309f0840d5d4c to your computer and use it in GitHub Desktop.
DNA pairing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The DNA strand is missing the pairing element. Take each character, get its pair, and return the results as a 2d array. | |
Base pairs are a pair of AT and CG. Match the missing element to the provided character. | |
Return the provided character as the first element in each array. | |
For example, for the input GCG, return [["G", "C"], ["C","G"],["G", "C"]] | |
The character and its pair are paired up in an array, and all the arrays are grouped into one encapsulating array. | |
*/ | |
function pairElement(str) { | |
str = str.split(''); | |
var holder = []; | |
for (var i = 0; i < str.length; i++) { | |
switch (str[i]) { | |
case 'A': | |
holder.push(['A', 'T']); | |
break; | |
case 'T': | |
holder.push(['T', 'A']); | |
break; | |
case 'C': | |
holder.push(['C', 'G']); | |
break; | |
case 'G': | |
holder.push(['G', 'C']); | |
break; | |
} | |
} | |
return holder; | |
} | |
pairElement('ATCGA'); | |
/* | |
Test youre code here | |
pairElement("ATCGA") should return [["A","T"],["T","A"],["C","G"],["G","C"],["A","T"]]. | |
pairElement("TTGAG") should return [["T","A"],["T","A"],["G","C"],["A","T"],["G","C"]]. | |
pairElement("CTCTA") should return [["C","G"],["T","A"],["C","G"],["T","A"],["A","T"]]. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment