-
Notifications
You must be signed in to change notification settings - Fork 242
/
symbols.go
53 lines (43 loc) · 1.03 KB
/
symbols.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
package utils
import "strings"
var renameMapping = map[string]string{
"STT": "SNT",
}
func RenameSymbols(symbols []string) (renames []string) {
for _, symbol := range symbols {
renames = append(renames, GetRealSymbol(symbol))
}
return
}
func RemoveDuplicates(strings []string) []string {
uniqueStrings := make(map[string]bool)
var uniqueSlice []string
for _, str := range strings {
if !uniqueStrings[str] {
uniqueStrings[str] = true
uniqueSlice = append(uniqueSlice, str)
}
}
return uniqueSlice
}
func GetRealSymbol(symbol string) string {
if val, ok := renameMapping[strings.ToUpper(symbol)]; ok {
return val
}
return strings.ToUpper(symbol)
}
func ChunkSymbols(symbols []string, chunkSizeOptional ...int) [][]string {
var chunks [][]string
chunkSize := 100
if len(chunkSizeOptional) > 0 {
chunkSize = chunkSizeOptional[0]
}
for i := 0; i < len(symbols); i += chunkSize {
end := i + chunkSize
if end > len(symbols) {
end = len(symbols)
}
chunks = append(chunks, symbols[i:end])
}
return chunks
}