mirror of
https://codeberg.org/pluja/kycnot.me
synced 2025-03-13 04:56:29 -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
@ -34,6 +34,21 @@ func (a *AttributeMap) GetAttributesFromList(attr string) []Attribute {
|
|||||||
return attributes
|
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 (
|
const (
|
||||||
AttributeRatingInfo = 0
|
AttributeRatingInfo = 0
|
||||||
AttributeRatingGood = 1
|
AttributeRatingGood = 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user