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
// Idiomatic solution using extrators | |
// Extractors allow us to bind parameters to an object and are usable in pattern matches to see if a pattern can apply to the params submitted. | |
// Note this is simialr to case classes, but works against an Object (which are like 'static' classes in Java). Also it incurs some performance penalties | |
// as opposed to using case classes | |
class BowlingForExtractors() { | |
def score(bowls:List[Int]) = scoreFrames(bowls).slice(0,10).sum // take the first 10 elements from the List and sum them..any additional elements are the result of additional strikes | |
def scoreFrames(bowls:List[Int]) : List[Int] = bowls match { | |
case Nil => List(0) |
NewerOlder