Farid finds an exhausting puzzle:
...snip.... I don't have a default case, because "Switch must be exhaustive". ...snip...
although the default case will never happen, so I returned nil instead and made my computed property an optional.
Nice approach!
Indeed, zero is not the right value to return if you're provided with an unusual value for toUnit
. You applied knowledge from Day 19 about optionals!
Is this the best approach? If not, what am I missing?
Maybe what you forgot is a lesson from Day 3!
See -> Power of enums
Your computed property relies on the value of toUnit
. Strings, like toUnit
can contain gazillion possible combinations of characters.
Can you refactor a solution where toUnit
contains possibilities limited to those you define in an enum
? Instead of defining toUnit
as a variable that holds a string
, what might be a better way to define toUnit
?
Give it a try and tell us how you updated your solution.
Keep coding! Keep asking questions.