Skip to content

Instantly share code, notes, and snippets.

@mikepack
Last active August 29, 2015 13:57
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 mikepack/9777411 to your computer and use it in GitHub Desktop.
Save mikepack/9777411 to your computer and use it in GitHub Desktop.
var DNA = function(sequence){
this.sequence = sequence;
this.nucleotideCounts = this._countNucleotides();
};
DNA.prototype = {
count: function(marker){
this._checkMarker(marker);
return this.sequence.split(marker).length - 1;
},
_countNucleotides: function(){
var counts = {};
for(var i = 0; i < this._displayedMarkers.length; i++){
var marker = this._displayedMarkers[i];
counts[marker] = this.count(marker);
}
return counts;
},
_checkMarker: function(marker){
if(this._acceptedMarkers.indexOf(marker) == -1){
throw(new Error("Invalid Nucleotide"));
};
},
_displayedMarkers: ['A', 'T', 'C', 'G'],
_acceptedMarkers: DNA.prototype._displayedMarkers + ['U']
}
module.exports = DNA;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment