This repository has been archived by the owner on Mar 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.go
113 lines (88 loc) · 2 KB
/
utils.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"fmt"
"reflect"
"sort"
"strconv"
"strings"
"time"
"github.com/fatih/color"
)
func colorPrintf(format string) {
color.New().Printf(format)
}
func isStringInStringArray(input string, list []string) bool {
for _, item := range list {
if input == item {
return true
}
}
return false
}
func stringToFloat(input string) (float64, error) {
return strconv.ParseFloat(input, 64)
}
func getSortedIntArrayAsFormattedString(list []int) string {
sort.Ints(list[:])
var output []string
for _, x := range list {
output = append(output, strconv.Itoa(x))
}
return strings.Join(output, ",")
}
func isInIntArray(x int, y []int) bool {
for _, z := range y {
if x == z {
return true
}
}
return false
}
func getFormattedOnlyInSideString(side string) string {
if side == "A" {
return color.HiGreenString("Only in A")
}
return color.HiMagentaString("Only in B")
}
func getFormattedSideString(side string) string {
if side == "A" {
return color.HiGreenString("A")
}
return color.HiMagentaString("B")
}
func getFormattedSideStringWithMessage(side, message string) string {
if side == "A" {
return color.HiGreenString(message)
}
return color.HiMagentaString(message)
}
func dedupeArray[T interface{}](array []T) []T {
result := []T{}
for _, item := range array {
found := false
for _, processedItem := range result {
if !found && reflect.DeepEqual(item, processedItem) {
found = true
}
}
if !found {
result = append(result, item)
}
}
return result
}
func formatDuration(duration time.Duration) string {
str := duration.String()
if duration.Hours() > 24 {
days := int(duration.Hours() / 24)
remainingHours := duration.Hours() - float64(days*24)
str = fmt.Sprintf("%dd %dh%s", days, int(remainingHours), strings.Split(str, "h")[1])
}
str = strings.Replace(str, "h", "h ", 1)
str = strings.Replace(str, "m", "m ", 1)
return str
}
func printTitle(title string) {
color.HiCyan("\n" + title)
fmt.Println(strings.Repeat("=", len(title)))
}