-
-
Save nirajkrz/0c13d8772ed423f247cb to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/nirajkrz 's solution for Bonfire: DNA Pairing
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
// 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