Javascript ordering and filtering in results