This version figures out the indexes needed to put the values of y in sorted order (the same order x uses), then splits it into sub-arrays based on value. The principle is simpler but the implementation looks like clear to me.
Note that these are only guaranteed to work on 1D arrays, I have not tested them on multidimensional arrays