Last active
July 26, 2017 18:00
-
-
Save gkio/818dea03039a9573216ee5b594e7bd54 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//ATCGCAT => TAGCGTA | |
// BEST | |
function DNAStrand(dna) { | |
return dna.replace(/./g, function(c) { | |
return DNAStrand.pairs[c] | |
}) | |
} | |
DNAStrand.pairs = { | |
A: 'T', | |
T: 'A', | |
C: 'G', | |
G: 'C', | |
} | |
// Good | |
var pairs = {'A':'T','T':'A','C':'G','G':'C'}; | |
function DNAStrand(dna){ | |
return dna.split('').map(function(v){ return pairs[v] }).join(''); | |
} | |
// One Line | |
function DNAStrand(dna) { | |
return dna.split('').map(function(v) {return {A:'T', T:'A', C:'G', G:'C'}[v];}).join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment