mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-04 12:52:28 +08:00
feat: add EqualUnordered
This commit is contained in:
@@ -44,6 +44,7 @@ import (
|
||||
- [Every](#Every)
|
||||
- [Equal](#Equal)
|
||||
- [EqualWith](#EqualWith)
|
||||
- [EqualUnordered](#EqualUnordered)
|
||||
- [Filter](#Filter)
|
||||
- [FilterConcurrent](#FilterConcurrent)
|
||||
- [Find<sup>deprecated</sup>](#Find)
|
||||
@@ -874,6 +875,37 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="EqualUnordered">EqualUnordered</span>
|
||||
|
||||
<p>检查两个切片是否相等,元素数量相同,值相等,不考虑元素顺序。</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func EqualUnordered[T comparable](slice1, slice2 []T) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/slice"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := slice.EqualUnordered([]int{1, 2, 3}, []int{3, 2, 1})
|
||||
result2 := slice.EqualUnordered([]int{1, 2, 3}, []int{4, 5, 6})
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="Filter">Filter</span>
|
||||
|
||||
<p>返回切片中通过predicate函数真值测试的所有元素</p>
|
||||
|
||||
@@ -43,6 +43,7 @@ import (
|
||||
- [DropRightWhile](#DropRightWhile)
|
||||
- [Equal](#Equal)
|
||||
- [EqualWith](#EqualWith)
|
||||
- [EqualUnordered](#EqualUnordered)
|
||||
- [Every](#Every)
|
||||
- [Filter](#Filter)
|
||||
- [FilterConcurrent](#FilterConcurrent)
|
||||
@@ -839,6 +840,37 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="EqualUnordered">EqualUnordered</span>
|
||||
|
||||
<p>Checks if two slices are equal: the same length and all elements' value are equal (unordered).</p>
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func EqualUnordered[T comparable](slice1, slice2 []T) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/slice"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := slice.EqualUnordered([]int{1, 2, 3}, []int{3, 2, 1})
|
||||
result2 := slice.EqualUnordered([]int{1, 2, 3}, []int{4, 5, 6})
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="Every">Every</span>
|
||||
|
||||
<p>Return true if all of the values in the slice pass the predicate function.</p>
|
||||
|
||||
Reference in New Issue
Block a user