Created
December 21, 2015 23:59
-
-
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."
This file contains 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
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