arns-lt-gemini/formatter.go
Arnas Udovicius 0cf5eb4d40
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
migrated to gPRC; about, all files
2022-08-20 01:03:57 +03:00

34 lines
593 B
Go

package main
import (
"sort"
)
func GetLastFiles(files []*TreeFile) []*TreeFile {
sortingFiles := make(map[string]*TreeFile)
for _, f := range files {
sortingFiles[f.Created+f.Id] = f
}
keys := make([]string, 0, len(sortingFiles))
for k := range sortingFiles {
keys = append(keys, k)
}
sort.Strings(keys)
sort.Reverse(sort.StringSlice(keys))
length := 10
if len(keys) < 10 {
length = len(keys)
}
lastFiles := make([]*TreeFile, 0, length)
for i, k := range keys {
if i == length {
break
}
lastFiles = append(lastFiles, sortingFiles[k])
}
return lastFiles
}