Return Value 戻り値
An array of the elements that is
allowed.
is
が許可する要素からなる配列。
Availability 有効性
Technology
func filter(_ isIncluded: (Self.Element) throws -> Bool
) rethrows -> [Self.Element]
An array of the elements that is
allowed.
is
が許可する要素からなる配列。
isIncluded
A closure that takes an element of the sequence as its argument and returns a Boolean value indicating whether the element should be included in the returned array. あるクロージャ、それは1つの要素をそれの引数として取り、その要素が返される配列に含まれるべきかどうかを指し示しているブール値を返します。
In this example, filter(_:)
is used to include only names shorter than five characters.
この例において、filter(_:)
は5つの文字より短い名前のみ含めるために使われます。
let cast = ["Vivien", "Marlon", "Kim", "Karl"]
let shortNames = cast.filter { $0.count < 5 }
print(shortNames)
// Prints "["Kim", "Karl"]"
Complexity
O(n), where n is the length of the sequence.