Last active
February 20, 2021 14:51
-
-
Save DaisukeNagata/e458e5997a90a16a0f2e8433fbfac7e8 to your computer and use it in GitHub Desktop.
check0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let numArray:[Int?] = [60, 70, 90, nil, 90, 0, 80, 80, 0, 80] | |
check() | |
func check() { | |
for (i, v) in numArray.enumerated() { | |
if ((numArray.firstIndex(where: { _ in 0 != v && v != nil })) != nil) { | |
print("インデックス: \(i)") | |
} | |
} | |
} |
Author
DaisukeNagata
commented
Jul 13, 2020
•
let numArray:[Int] = [60, 0, 0, 0, 90, 0, 80, 80, 0, 80]
check()
func check() {
for (i, v) in numArray.enumerated() {
if numArray.firstIndex(where: { _ in 0 != v }) != nil {
print("index: \(i)")
} else {
print("value0: \(i)")
}
}
}
extension Array where Element: Equatable {
func checkArray(value: [Element]) -> Bool{
var flg = false
value.forEach { v in
if (self.firstIndex(of: v) != nil) {
flg = true
}
}
return flg
}
}
var b = [11,22]
a ()
func a (){
print(b.checkArray(value: [111,22,333])) // true
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment