Skip to content

Instantly share code, notes, and snippets.

Created December 3, 2015 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/85804e38513a58a3d2dc to your computer and use it in GitHub Desktop.
Save anonymous/85804e38513a58a3d2dc to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/nirajkrz 's solution for Bonfire: DNA Pairing
// Bonfire: DNA Pairing
// Author: @nirajkrz
// Challenge: http://www.freecodecamp.com/challenges/bonfire-dna-pairing
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function pair(str) {
/*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"]]*/
// Return each strand as an array of two elements, the original and the pair.
var paired = [];
// Function to check with strand to pair.
var search = function(str) {
switch (str) {
case 'A':
paired.push(['A', 'T']);
break;
case 'T':
paired.push(['T', 'A']);
break;
case 'C':
paired.push(['C', 'G']);
break;
case 'G':
paired.push(['G', 'C']);
break;
}
};
// Loops through the input and pair.
console.log(str);
for (var i = 0; i < str.length; i++) {
search(str[i]);
}
return paired;
}
pair("GCG");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment