-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
64 lines (57 loc) · 1.5 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"slices"
"strings"
"time"
)
func Mask(in string) string {
if len(in) < 3 {
return in
}
return in[0:3] + "****" + in[len(in)-3:]
}
func DurDay(start, end time.Time) int {
start = start.Truncate(24 * time.Hour)
end = end.Truncate(24 * time.Hour)
diff := end.Sub(start)
return int(diff.Hours() / 24)
}
func AllAirlineName(flights []Flight) []string {
airlineMaps := make(map[string]struct{})
for _, flight := range flights {
airlineMaps[flight.AirlineName] = struct{}{}
}
airlineNames := make([]string, 0, len(airlineMaps))
for k := range airlineMaps {
airlineNames = append(airlineNames, k)
}
slices.Sort(airlineNames)
return airlineNames
}
func AllAirlineCode(flights []Flight) []string {
airlineCodeMaps := make(map[string]struct{})
for _, flight := range flights {
airlineCode := strings.Split(flight.FlightNumber, " ")[0]
airlineCodeMaps[airlineCode] = struct{}{}
}
airlineCodes := make([]string, 0, len(airlineCodeMaps))
for k := range airlineCodeMaps {
airlineCodes = append(airlineCodes, k)
}
slices.Sort(airlineCodes)
return airlineCodes
}
func AllFlightNumber(flights []Flight) []string {
flightNumbers := make([]string, 0, len(flights))
for _, flight := range flights {
flightNumbers = append(flightNumbers, flight.FlightNumber)
}
return flightNumbers
}
func AllMetadata(flights []Flight) []string {
metadatas := make([]string, 0, len(flights))
for _, flight := range flights {
metadatas = append(metadatas, flight.String())
}
return metadatas
}