Skip to content

Instantly share code, notes, and snippets.

@mathildathompson
Created May 9, 2014 00:09
Show Gist options
  • Save mathildathompson/f751c4720525774745fd to your computer and use it in GitHub Desktop.
Save mathildathompson/f751c4720525774745fd to your computer and use it in GitHub Desktop.
var DNAStringFactory = function(string){
var DNA = {
string: string,
count: function(letter){
if (!_.contains(['A', 'G', 'C', 'T', 'U'], letter)){
return alert('This is not valid!');
}
var result = _.filter(this.string, function(nucleotide){
return nucleotide == letter;
})
return result.length;
},
nucleotidesCount: function(){
var nucleotideHash = {}
_.each(this.string, function(nucleotide){
nucleotideHash[nucleotide] = nucleotideHash[nucleotide] || 0;
nucleotideHash[nucleotide]++;
})
return nucleotideHash;
}
}
return DNA;
}
var dna = DNAStringFactory('AGGTGGU')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment