【发布时间】:2015-10-08 21:31:00
【问题描述】:
说,我有一个数组 let array = [ "foo", "bar", "baz", "foobar", "qux" ] 和这个数组内的索引 3。我想按以下顺序迭代数组中的所有元素foobar(索引 3 处的元素)、qux(索引 4)、foo(索引 0 等)、bar、@987654326 @。
不太优雅的解决方案如下所示:
for index in givenIndex ..< array.endIndex {
// do some work with array[index]
}
for index in array.startIndex ..< givenIndex {
// do the same work with array[index]
}
有没有更优雅的解决方案?
【问题讨论】: