Skip to main content
Glama
slice.go1.3 kB
package utils // RemoveEmptyLines 删除字符串切片中的空行 func RemoveEmptyLines(lines []string) []string { result := make([]string, 0, len(lines)) for _, line := range lines { if line != "" { result = append(result, line) } } return result } // AllIn 判断A数组中的元素,是否都在B数组中 // a := []string{"apple", "banana"} // b := []string{"apple", "banana", "cherry"} // // fmt.Println(AllIn(a, b)) // true // // a2 := []string{"apple", "kiwi"} // fmt.Println(AllIn(a2, b)) // false func AllIn(a, b []string) bool { bSet := make(map[string]struct{}, len(b)) for _, item := range b { bSet[item] = struct{}{} } for _, item := range a { if _, ok := bSet[item]; !ok { return false } } return true } // AnyIn 判断A数组中的元素,是否有任意一个存在于B数组中 // a := []string{"apple", "kiwi"} // b := []string{"apple", "banana", "cherry"} // // fmt.Println(AnyIn(a, b)) // true,因为"apple"在b中 // // a2 := []string{"grape", "kiwi"} // fmt.Println(AnyIn(a2, b)) // false,因为没有元素在b中 func AnyIn(a, b []string) bool { bSet := make(map[string]struct{}, len(b)) for _, item := range b { bSet[item] = struct{}{} } for _, item := range a { if _, ok := bSet[item]; ok { return true } } return false }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/weibaohui/k8m'

If you have feedback or need assistance with the MCP directory API, please join our Discord server