优化uniqueue返回值
This commit is contained in:
parent
3caad964bc
commit
e228983e73
10
array.go
10
array.go
@ -65,8 +65,8 @@ func (at *Array[Bt]) ToStringSlice() []string {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 17:43 2023/6/12
|
// Date : 17:43 2023/6/12
|
||||||
func (at *Array[Bt]) Unique() StringResult {
|
func (at *Array[Bt]) Unique() []Bt {
|
||||||
result := make([]any, 0)
|
result := make([]Bt, 0)
|
||||||
dataTable := make(map[string]bool)
|
dataTable := make(map[string]bool)
|
||||||
|
|
||||||
for _, item := range at.value {
|
for _, item := range at.value {
|
||||||
@ -81,11 +81,7 @@ func (at *Array[Bt]) Unique() StringResult {
|
|||||||
dataTable[k] = true
|
dataTable[k] = true
|
||||||
result = append(result, item)
|
result = append(result, item)
|
||||||
}
|
}
|
||||||
byteData, _ := json.Marshal(result)
|
return result
|
||||||
return StringResult{
|
|
||||||
Value: string(byteData),
|
|
||||||
Err: nil,
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestArray_Unique(t *testing.T) {
|
func TestArray_Unique(t *testing.T) {
|
||||||
fmt.Println(ArrayType([]any{"1", 1, 1, "1", 2, 3}).Unique().Value)
|
fmt.Println(ArrayType([]any{"1", 1, 1, "1", 2, 3}).Unique())
|
||||||
fmt.Println(ArrayType([]int{1, 1, 2, 3}).Unique().Value)
|
fmt.Println(ArrayType([]int{1, 1, 2, 3}).Unique())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user