C
C#2y ago
Gladiator

❔ Can I use slice operator with loop index (remainder operator%)?

I want to slice an array from start to end index but if end index exceeds the array length, loop it and start from index 0 (remainder operator%)
7 Replies
sibber
sibber2y ago
but then the end index could be smaller than the start index
Gladiator
GladiatorOP2y ago
So? I have to use array index with remainder operator and add these elements to a list? Array with 10 elements. Start from index 8 and length 5 Index 8,9,0,1,2 For example
sibber
sibber2y ago
oh thats what you meant what if the length is 12 do items get repeated, or just returns the last 2 items? i guess the latter makes more sense
Gladiator
GladiatorOP2y ago
I do no know what you mean It was an example. If the length is 12 and start from index 8 with 5 length, it returns 8,9,10,11,0
sibber
sibber2y ago
not the length of the array same array of 10 elements start at index 8 with length 12 instead of 5
Gladiator
GladiatorOP2y ago
I said it should be looped so 8,9,0,1,2,...9 I do not know what is the difference? but this sequence length is max 10 (array element size) in my scenario
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server