Using Reduce Method Javascript Array Sort Algorithm