Recently I encountered the issue of converting a degree in ° (0-360) to a direction (compass directions). On my internet research I only found “ugly” solutions where the minAngle and maxAngle were explicitly listed for each direciont (N, NNE, NE, NEE…).
There was no chance that I would copy such ugly code into my codebase, therefore it made the effort to think about a more beautful way to solve this task. In the end, I came up with this: