-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup.go
55 lines (44 loc) · 794 Bytes
/
group.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
/*
* Ali Ahmadi
* Dedicated to MHM
*/
package num2text
import (
"slices"
)
// group number to group of 3 digits
// func group(num string) []string {
// g := make([]string, 0)
// chs := strings.Split(num, "")
// str := ""
// c := 0
// for i := len(chs) - 1; i >= 0; i-- {
// if c == 3 {
// c = 1
// g = append(g, reverse(str))
// str = ""
// str += chs[i]
// } else {
// c++
// str += chs[i]
// }
// }
// if str != "" {
// g = append(g, reverse(str))
// }
// slices.Reverse(g)
// return g
// }
func group(num string) []string {
groups := []string{}
for len(num) > 2 {
gr := num[len(num)-3:]
groups = append(groups, gr)
num = num[:len(num)-3]
}
if num != "" {
groups = append(groups, num)
}
slices.Reverse(groups)
return groups
}