Sort Objects In Array Javascript Function