Rule expression function sort() for array of strings

Would like to be able to sort an array of strings alphabetically. I’ve tried sort() in expressions just for the heck of it, but it only works with an array of numbers. Any way to add string support?

My use case: I have a rule that queries the Smartthings API to get an array of devices that are lights or switches, and then I filter it to include only those that are ON. I then filter that array with a known list of exclusions (lights or switches that are normally on) and then map to get the labels for the devices remaining in the list. I use this to send a notification to let me know which lights I left on, which locks are unlocked, etc. I’d find it easier to read the list if it were sorted alphabetically. “Garden light” is a child device and I couldn’t figure out how to get it to play like the others, so I treat it specially by jamming its status at the end of the array. This routine runs very fast (much faster than a zillion if device status=ON checks, which was how I wrote it initially before the expression editor existed).

Here’s how I’m evaluating the list I’d like to sort…would like to sort just before the join at the end. Thanks!

inclusions = ["on"]

myArray = parseJson($X).items
myArray2 = filter(myArray, contains(x.components[0].capabilities[0].status.switch.value,inclusions))
myArray3 = map(myArray2, x.label)

idx = count(myArray3) 

myArray3[idx] = equalText(upper($foo),"ON") ? "Garden Light" : ":"

exclusions = ["Madison Lights",":","Downspout Heater","Coffee Maker","GFCI Monitor","US Turntable","TiVo stream DS plug","Utility Room Heater","TiVo 1-stream 2-mini"]

filteredItems = filter(myArray3, not(contains(exclusions, x)))

join(filteredItems, ", ")