Javascript sorting algorithms