sliceutil

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2020 License: MIT Imports: 2 Imported by: 34

README

sliceutil Build Status license codecov

sliceutil 提供了针对数组和切片的功能

  • Count 统计数组或切片中包含指定什的数量;
  • Dup 查看数组或切片中是否包含重得的值;

安装

go get github.com/issue9/sliceutil

文档

go.dev reference

版权

本项目采用 MIT 开源授权许可证,完整的授权说明可在 LICENSE 文件中找到。

Documentation

Overview

Package sliceutil 提供对数组和切片的相关功能

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Count

func Count(slice interface{}, eq func(i int) bool) (count int)

Count 检测数组中指定值的数量

slice 需要检测的数组或是切片,其它类型会 panic; eq 对比函数,i 表示数组的下标,需要在函数将该下标表示的值与你需要的值进行比较是否相等;

Example
intSlice := []int{1, 2, 3, 7, 0, 4, 7}
fmt.Println(Count(intSlice, func(i int) bool {
	return intSlice[i] == 7
}))
Output:

2

func Dup

func Dup(slice interface{}, eq func(i, j int) bool) int

Dup 检测数组中是否包含重复的值

slice 需要检测的数组或是切片,其它类型会 panic; eq 对比数组中两个值是否相等,相等需要返回 true; 返回值表示存在相等值时,第二个值在数组中的下标值;

Example
intSlice := []int{1, 2, 3, 7, 0, 4, 7}
fmt.Println(Dup(intSlice, func(i, j int) bool {
	return intSlice[i] == intSlice[j]
}))
Output:

6

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL