Created
September 16, 2021 08:32
-
-
Save ajaysinghthakur/d51f80151d0c78cdf3efc246906e879a to your computer and use it in GitHub Desktop.
Iterate an array from the any index then the beginning, can transverse array all element from any starting index
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let a = [1,2,3,4,5,6] | |
let startIndex = 5 | |
let endIndex = a.count | |
for i in stride(from: 0, to: endIndex, by: 1) { | |
let newIndex = (i + startIndex) % endIndex | |
print(newIndex) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment