package comm

type Person struct {
	Name string
	Age  int
	Sex  bool
	ID   int
}

type PersonSlice []Person

// Less 没有实现sort.Interface的Less方法
func (p PersonSlice) Less(i, j int, field string) bool {
	return PersonByField(p[i], p[j], field)
}

// PersonByField 按照字段排序
func PersonByField(i, j Person, field string) bool {
	switch field {
	case "Name":
		return i.Name > j.Name
	case "Age":
		return i.Age < j.Age
	case "Sex":
		return i.Sex != j.Sex
	case "ID":
		return i.ID < j.ID
	}
	return false
}
