Created
March 26, 2014 12:45
-
-
Save Yardboy/9782322 to your computer and use it in GitHub Desktop.
Removing all that this. Alternate version of https://github.com/jcasimir/exercism_solutions/blob/master/javascript/nucleotide-count/nucleotide-count.js
This file contains 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 DNA = function(sequence) { | |
var count, checkMarker; | |
var nucleotideCounts = {}; | |
var displayedMarkers = ['A', 'T', 'C', 'G']; | |
var acceptedMarkers = displayedMarkers + ['U']; | |
count = function(marker){ | |
checkMarker(marker); | |
return sequence.split(marker).length - 1; | |
} | |
checkMarker = function(marker){ | |
if(acceptedMarkers.indexOf(marker) == -1){ | |
throw(new Error("Invalid Nucleotide")); | |
} | |
} | |
for(var i = 0; i < displayedMarkers.length; i++){ | |
var marker = displayedMarkers[i]; | |
nucleotideCounts[marker] = count(marker); | |
} | |
return { | |
count: function(marker) { | |
return count(marker) | |
}, | |
nucleotideCounts: nucleotideCounts | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment