randomforestwhitaker / questions

questions
0 stars 0 forks source link

define `average` for empty lists #8

Closed adampingel closed 6 years ago

adampingel commented 6 years ago

https://github.com/randomforestwhitaker/questions/blob/a607680fed8c614a478260e329b4412a57112903/answer_1.scala#L43-L45

This helper function would be more helpful if it were defined on empty lists. Check the incoming list's length. If it's zero, return Double.NaN.

This would allow you to remove the check for Nil in resolver above.

randomforestwhitaker commented 6 years ago

Moved empty list handling logic to this average helper function instead of main resolver function.