Asynchronous qsort implemented in JavaScript