Skip to content

Instantly share code, notes, and snippets.

@denmch
Created December 21, 2015 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save denmch/4529fe0858744dacf6b8 to your computer and use it in GitHub Desktop.
Save denmch/4529fe0858744dacf6b8 to your computer and use it in GitHub Desktop.
"The DNA strand is missing the pairing element. Take each character, get its pair, and return the results as a 2d array."
function pair(str) {
var tmp = str.split(''), // Make a copy without altering str
match = { // An object to easily match pairs
'C': 'G',
'G': 'C',
'A': 'T',
'T': 'A'
},
result = [], // Initialize some variables
currentPair,
letter;
while (tmp.length > 0) {
letter = tmp.shift(); // Also acts as the iterator :thumbsup:
currentPair = [letter, match[letter]]; // Match it up!
result.push(currentPair); // Push it … push it real good
}
return result;
}
pair("GCG");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment