Help to simplify/optimize a function

I like this approach. Simple elegant solution. Never thought about match?