fix sorted() (#674)

This commit is contained in:
Leo
2016-12-26 19:51:31 +08:00
committed by 安正超
parent ef577dbad4
commit de4a848d6f

View File

@ -12,10 +12,10 @@
> 校对:[shanks](http://codebuild.me) > 校对:[shanks](http://codebuild.me)
> 2.2 > 2.2
> 校对:[SketchK](https://github.com/SketchK) 2016-05-11 > 校对:[SketchK](https://github.com/SketchK) 2016-05-11
> >
> 3.0 > 3.0
> 校对:[shanks](http://codebuild.me) 2016-10-09 > 校对:[shanks](http://codebuild.me) 2016-10-09
> 3.0.1shanks2016-11-12 > 3.0.1shanks2016-11-12
@ -23,7 +23,7 @@
- [集合的可变性](#mutability_of_collections) - [集合的可变性](#mutability_of_collections)
- [数组](#arrays) - [数组](#arrays)
- [集合](#sets) - [集合](#sets)
- [集合操作](#performing_set_operations) - [集合操作](#performing_set_operations)
- [字典](#dictionaries) - [字典](#dictionaries)
@ -86,7 +86,7 @@ someInts = []
Swift 中的`Array`类型还提供一个可以创建特定大小并且所有数据都被默认的构造方法。我们可以把准备加入新数组的数据项数量(`count`)和适当类型的初始值(`repeating`)传入数组构造函数: Swift 中的`Array`类型还提供一个可以创建特定大小并且所有数据都被默认的构造方法。我们可以把准备加入新数组的数据项数量(`count`)和适当类型的初始值(`repeating`)传入数组构造函数:
```swift ```swift
var threeDoubles = Array(repeating: 0.0, count: 3) var threeDoubles = Array(repeating: 0.0, count: 3)
// threeDoubles 是一种 [Double] 数组,等价于 [0.0, 0.0, 0.0] // threeDoubles 是一种 [Double] 数组,等价于 [0.0, 0.0, 0.0]
``` ```
@ -96,7 +96,7 @@ var threeDoubles = Array(repeating: 0.0, count: 3)
我们可以使用加法操作符(`+`)来组合两种已存在的相同类型数组。新数组的数据类型会被从两个数组的数据类型中推断出来: 我们可以使用加法操作符(`+`)来组合两种已存在的相同类型数组。新数组的数据类型会被从两个数组的数据类型中推断出来:
```swift ```swift
var anotherThreeDoubles = Array(repeating: 2.5, count: 3) var anotherThreeDoubles = Array(repeating: 2.5, count: 3)
// anotherThreeDoubles 被推断为 [Double],等价于 [2.5, 2.5, 2.5] // anotherThreeDoubles 被推断为 [Double],等价于 [2.5, 2.5, 2.5]
var sixDoubles = threeDoubles + anotherThreeDoubles var sixDoubles = threeDoubles + anotherThreeDoubles
@ -202,7 +202,7 @@ shoppingList[4...6] = ["Bananas", "Apples"]
调用数组的`insert(_:at:)`方法来在某个具体索引值之前添加数据项: 调用数组的`insert(_:at:)`方法来在某个具体索引值之前添加数据项:
```swift ```swift
shoppingList.insert("Maple Syrup", at: 0) shoppingList.insert("Maple Syrup", at: 0)
// shoppingList 现在有7项 // shoppingList 现在有7项
// "Maple Syrup" 现在是这个列表中的第一项 // "Maple Syrup" 现在是这个列表中的第一项
``` ```
@ -448,7 +448,7 @@ let oddDigits: Set = [1, 3, 5, 7, 9]
let evenDigits: Set = [0, 2, 4, 6, 8] let evenDigits: Set = [0, 2, 4, 6, 8]
let singleDigitPrimeNumbers: Set = [2, 3, 5, 7] let singleDigitPrimeNumbers: Set = [2, 3, 5, 7]
oddDigits.union(evenDigits).sort() oddDigits.union(evenDigits).sorted()
// [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
oddDigits. intersection(evenDigits).sorted() oddDigits. intersection(evenDigits).sorted()
// [] // []