Generic Instance Method 総称体インスタンスメソッド

lexicographicallyPrecedes(_:)

Returns a Boolean value indicating whether the sequence precedes another sequence in a lexicographical (dictionary) ordering, using the less-than operator (<) to compare elements. そのシーケンスが別のシーケンスの前に来るかどうかを、ある語彙筆記的順序(字典)順序において、より小さい演算子(<)を使って要素を比較して、指し示すブール値を返します。

Declaration 宣言

func lexicographicallyPrecedes<OtherSequence>(_ other: OtherSequence) -> Bool where OtherSequence : Sequence, Element == OtherSequence.Element
Available when Element conforms to Comparable. ElementComparableに準拠する時に利用可能です。

Parameters パラメータ

other

A sequence to compare to this sequence. あるシーケンス、このシーケンスと比べることになります。

Return Value 戻り値

true if this sequence precedes other in a dictionary ordering; otherwise, false. このシーケンスがotherに、ある字典順序において先行するならば、true;そうでなければ、false

Discussion 解説

This example uses the lexicographicallyPrecedes method to test which array of integers comes first in a lexicographical ordering. この例はlexicographicallyPrecedesメソッドを使って、どの整数配列がある語彙筆記的順序において最初に来るかをテストします。


let a = [1, 2, 2, 2]
let b = [1, 2, 3, 4]


print(a.lexicographicallyPrecedes(b))
// Prints "true"
print(b.lexicographicallyPrecedes(b))
// Prints "false"

Complexity: O(m), where m is the lesser of the length of the sequence and the length of other. 計算量:O(m)、ここでmはシーケンスの長さとotherの長さのより短い方です。

See Also 参照

Comparing Arrays 配列の比較