3 ms·
That only works if you're ranging from 0 to n-1, though. A popular way to partition an array at i and j is to do: arr[0..<i], arr[i..<j], arr[j...-1]
by Zarel 7y ago
That only works if you're ranging from 0 to n-1, though.
A popular way to partition an array at i and j is to do:
arr[0..<i], arr[i..<j], arr[j...-1]
- a1369209993 7y agoa0,a1,a2 = arr.splitat({i,j}) maybe? It avoids repeating i and j twice and arr thrice, at least. Admittedly, there probably are cases where you really do want a range [x..^y] for arbitrary x and y, but it seems like most cases aren't.