Sorting Algorithm In Javascript Object Array