我正在尝试检查一个数组是否包含一个特定的单词和另一个数组,如下所示:
我要怎么在戈朗做这件事。我尝试了一堆步骤,我回到了第一步,到目前为止,我所拥有的是:
func compare(firstString, secondString string) bool {
return false
}
compare("3 of hearts", "5 of hearts")
## This should return true发布于 2022-05-18 09:47:07
我对golang相当陌生,但是不需要循环两次就能得到这个结果的最好方法是:
func compare(firstString, secondString string) bool {
f, s := strings.Split(f, " "), strings.Split(secondString, " ")
if f[0] == s[0] || f[2] == f[2] {
return true
}
return false
}
compare("3 of hearts", "5 of hearts")
## This should return true
compare("7 of hearts", "7 of clubs")
## This should return true
compare("Jack of spades", "Jack of spades")
## This should return true
compare("5 of hearts", "7 of clubs")
## This should return falsehttps://stackoverflow.com/questions/72281334
复制相似问题