Skip to content

Instantly share code, notes, and snippets.

@DaisukeNagata
Last active February 20, 2021 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaisukeNagata/e458e5997a90a16a0f2e8433fbfac7e8 to your computer and use it in GitHub Desktop.
Save DaisukeNagata/e458e5997a90a16a0f2e8433fbfac7e8 to your computer and use it in GitHub Desktop.
check0
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)")
}
}
}
@DaisukeNagata
Copy link
Author

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