src/main/scala/nucleotide_count.scala

1
2
3
4
5
6
7
8
9
10
object DNA {
  val EmptyMap = Map('A' -> 0, 'C' -> 0, 'G' -> 0, 'T' -> 0)
}

class DNA(sequence: String) {
  require(sequence.matches("^[ACGT]*$"))

  val nucleotideCounts = DNA.EmptyMap ++
       sequence.groupBy(identity).mapValues(_ length)
}

Comments


You're not logged in right now. Please login via GitHub to comment