refactor: reverse list function finally

This commit is contained in:
cellarspoon 2021-12-28 02:31:06 +01:00
parent bac6fb0fa8
commit 43e68a99b0
Signed by untrusted user: decentral1se
GPG Key ID: 03789458B3D0C410
4 changed files with 14 additions and 6 deletions

View File

@ -183,9 +183,7 @@ can take some time.
stats.latestCount++
}
} else {
for i, j := 0, len(newUpdates)-1; i < j; i, j = i+1, j-1 {
newUpdates[i], newUpdates[j] = newUpdates[j], newUpdates[i]
}
newUpdates = internal.ReverseStringList(newUpdates)
appStats.upgrade = strings.Join(newUpdates, "\n")
stats.upgradeCount++
}

View File

@ -112,9 +112,7 @@ recipes.
}
}
for i, j := 0, len(availableDowngrades)-1; i < j; i, j = i+1, j-1 {
availableDowngrades[i], availableDowngrades[j] = availableDowngrades[j], availableDowngrades[i]
}
availableDowngrades = internal.ReverseStringList(availableDowngrades)
var chosenDowngrade string
if !internal.Chaos {

View File

@ -119,6 +119,8 @@ recipes.
}
}
availableUpgrades = internal.ReverseStringList(availableUpgrades)
var chosenUpgrade string
if len(availableUpgrades) > 0 && !internal.Chaos {
if internal.Force {

10
cli/internal/list.go Normal file
View File

@ -0,0 +1,10 @@
package internal
// ReverseStringList reverses a list of a strings. Roll on Go generics.
func ReverseStringList(strings []string) []string {
for i, j := 0, len(strings)-1; i < j; i, j = i+1, j-1 {
strings[i], strings[j] = strings[j], strings[i]
}
return strings
}