Created
May 9, 2014 00:09
-
-
Save mathildathompson/f751c4720525774745fd 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
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