PHP insertion sort and javascript insertion sort