mirror of
https://codeberg.org/pluja/kycnot.me
synced 2025-07-08 23:59:49 -04:00
🔀 refactor(attributes.go): extract sorting logic into a separate method for better code organization and reusability
This commit is contained in:
parent
d84a7c95bf
commit
910a779f66
1 changed files with 15 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue