🔀 refactor(attributes.go): extract sorting logic into a separate method for better code organization and reusability

This commit is contained in:
pluja 2023-10-31 17:58:19 +01:00
parent d84a7c95bf
commit 910a779f66

View File

@ -34,6 +34,21 @@ func (a *AttributeMap) GetAttributesFromList(attr string) []Attribute {
return attributes
}
func (a *AttributeMap) GetSortedAttributes(reverse bool) []Attribute {
// Return the attributes sorted by Rating from best to worst
attributes := make([]Attribute, 0, len(a.Attributes))
for _, attr := range a.Attributes {
attributes = append(attributes, attr)
}
sort.Slice(attributes, func(i, j int) bool {
if reverse {
return attributes[i].Rating > attributes[j].Rating
}
return attributes[i].Rating < attributes[j].Rating
})
return attributes
}
const (
AttributeRatingInfo = 0
AttributeRatingGood = 1