Skip to content

Instantly share code, notes, and snippets.

@jepras
Created September 29, 2018 08:06
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 jepras/5ff0186450f20d795fdcad1d44c6de26 to your computer and use it in GitHub Desktop.
Save jepras/5ff0186450f20d795fdcad1d44c6de26 to your computer and use it in GitHub Desktop.
Created a function that takes in a parameter, that is then looped and called until end. Function is a switch statement.
// Docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch
// https://guide.freecodecamp.org/certifications/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/dna-pairing
function pairElement(str) {
var paired = [];
var search = function(char) {
switch (char) {
case 'A':
console.log("a found");
paired.push(['A', 'T']);
break;
case 'T':
console.log("t found");
paired.push(['T', 'A']);
break;
case 'C':
console.log("c found");
paired.push(['C','G']);
break;
case 'G':
console.log("g found");
paired.push(['G','C']);
break;
}
}
for (var i = 0; i < str.length; i++) {
search(str[i]);
}
return paired;
}
pairElement("GCG");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment