Introsort implemented in Javascript