This script demonstrates how to sort task list items by categories in Office 365 Exchange Online. Technically, this script add category name as a prefix in the Subject property of a task item. Then you need to use Arrange by Subject in Outlook Web App (OWA).
Currently, you can easily group the task items by categories in Outlook. But you cannot do the same thing in Outlook Web App (OWA). So you need a workaround to mitigate this problem if you only use Outlook Web App (OWA).
You can find more All-In-One Script Framework script samples at https://aka.ms/onescriptingallery