Skip to content

Instantly share code, notes, and snippets.

@gkio
Last active July 26, 2017 18:00
Show Gist options
  • Save gkio/818dea03039a9573216ee5b594e7bd54 to your computer and use it in GitHub Desktop.
Save gkio/818dea03039a9573216ee5b594e7bd54 to your computer and use it in GitHub Desktop.
//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