Hmm... here's my version of this. I'm wondering which would be more efficient, or if mine is bad practice. It's just what came to my mind first. The changes from the original code are under the // comments

Hmm.. the most efficient is probably caching the sortType? check like your last one, but maybe adding it to the data like I did so there is no need for the data assigning loop (if that's possible ... )