Last active
June 15, 2018 17:56
-
-
Save eday69/b04fdbc44857bd6e9c3d5043e2bd69e8 to your computer and use it in GitHub Desktop.
freeCodeCamp Intermediate Algorithm Scripting: 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
// 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) { | |
let myArr={"A" : "T", "T" : "A", "G" : "C", "C" : "G"}; | |
return str.split("").map(dna => [dna, myArr[dna]] ); | |
} | |
pairElement("GCG"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment