📜  快速获取数组的前 n 个元素 - Swift 代码示例

📅  最后修改于: 2022-03-11 15:00:58.984000             🧑  作者: Mango

代码示例1
// the neatest way to get the first N elements of a Swift array is using
// prefix(_ maxLength: Int):
let someArray = [1, 2, 3, 4, 5, 6, 7]
let first5 = someArray.prefix(5) // 1, 2, 3, 4, 5