1
以下のような記述がありますか?または関数を作成する必要がありますか?Swift 3.0に「もしあれば」と似た記述がありますか?
let x=[Double](1.023, 2.023, 3.023, 4.023, 5.023)
ler y=[Double](3.001)
if any of x > y{
("YES")}
以下のような記述がありますか?または関数を作成する必要がありますか?Swift 3.0に「もしあれば」と似た記述がありますか?
let x=[Double](1.023, 2.023, 3.023, 4.023, 5.023)
ler y=[Double](3.001)
if any of x > y{
("YES")}
配列のcontains(where:)
メソッドを使用できます。
let x = [1.023, 2.023, 3.023, 4.023, 5.023]
let y = 3.001
if x.contains(where: { $0 > y }) {
print("YES")
}
あなたが大きかった最初の値を知りたい場合は、あなたが行うことができます:
let x = [1.023, 2.023, 3.023, 4.023, 5.023]
let y = 3.001
if let firstLarger = x.first(where: { $0 > y }) {
print("Found \(firstLarger)")
}
あなたが大きくなっていることすべてを知りたい場合は、あなたがfilter
を使用することができます。
let x = [1.023, 2.023, 3.023, 4.023, 5.023]
let y = 3.001
let matches = x.filter { $0 > y }
print("The following are greater: \(matches)")
let x = [1.023, 2.023, 3.023, 4.023, 5.023]
let y = [3.001]
let result = x.filter { $0 > y[0] }
print(result) // [3.023, 4.023, 5.023]
これはスウィフトではありません。あなたの実際のコードを投稿してください。 yが単に配列(配列ではない)であれば、contains(where :) {if x.contains(where:{$ 0> y}){ print(true) } –