-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArrayUtils.xojo_code
794 lines (651 loc) · 22.6 KB
/
ArrayUtils.xojo_code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
#tag Module
Protected Module ArrayUtils
#tag Method, Flags = &h0
Sub Add(Extends arr() As Double, arr2() As Double)
// Concatenate arr2 to arr.
Var ub2 As Integer = arr2.LastIndex
if ub2 < 0 then return
Var base As Integer = arr.count
arr.ResizeTo( base + ub2 )
Var index As Integer
for index = 0 to ub2
arr( base + index ) = arr2( index )
next
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub add(Extends arr() As Integer, arr2() As Integer)
// Concatenate arr2 to arr.
Var ub2 As Integer = arr2.LastIndex
if ub2 < 0 then return
Var base As Integer = arr.count
arr.ResizeTo( base + ub2 )
Var index As Integer
for index = 0 to ub2
arr( base + index ) = arr2( index )
next
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub add(Extends arr() As String, arr2() As String)
// Concatenate arr2 to arr.
Var ub2 As Integer = arr2.LastIndex
if ub2 < 0 then return
Var base As Integer = arr.count
arr.ResizeTo( base + ub2 )
Var index As Integer
for index = 0 to ub2
arr( base + index ) = arr2( index )
next
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Function Average(Extends arr() As Double) As Double
// Return the arithmetic mean of the values in the array.
Var item, sum As Double
for each item in arr
sum = sum + item
next
return sum / ( arr.count )
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function Average(Extends arr() As Integer) As Double
// Return the arithmetic mean of the values in the array.
Var item, sum As Integer
for each item in arr
sum = sum + item
next
return sum / ( arr.count)
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function Clone(Extends arr() As Double) As Double()
// Return an independent copy of this array.
Var out() As Double
Var ub As Integer = arr.LastIndex
if ub >= 0 then
ReDim out( ub )
Var index As Integer
for index = 0 to ub
out( index ) = arr( index )
next
end if
return out
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function Clone(Extends arr() As Integer) As Integer()
// Return an independent copy of this array.
Var out() As Integer
Var ub As Integer = arr.LastIndex
if ub >= 0 then
ReDim out( ub )
Var index As Integer
for index = 0 to ub
out( index ) = arr( index )
next
end if
return out
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function Clone(Extends arr() As String) As String()
// Return an independent copy of this array.
Var out() As String
Var ub As Integer = arr.LastIndex
if ub >= 0 then
ReDim out( ub )
Var index As Integer
for index = 0 to ub
out( index ) = arr( index )
next
end if
return out
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function Concat(Extends arr1() As Double, arr2() As Double) As Double()
// Concatenate arr2 to arr1 and return the result as a new array.
Var out() As Double
Var ub1 As Integer = arr1.LastIndex
Var ub2 As Integer = arr2.LastIndex
ReDim out( ub1 + ub2 + 1 )
Var index, base As Integer
for index = 0 to ub1
out( index ) = arr1( index )
next
base = ub1 + 1
for index = 0 to ub2
out( base + index ) = arr2( index )
next
return out
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function Concat(Extends arr1() As Integer, arr2() As Integer) As Integer()
// Concatenate arr2 to arr1 and return the result as a new array.
Var out() As Integer
Var ub1 As Integer = arr1.LastIndex
Var ub2 As Integer = arr2.LastIndex
ReDim out( ub1 + ub2 + 1 )
Var index, base As Integer
for index = 0 to ub1
out( index ) = arr1( index )
next
base = ub1 + 1
for index = 0 to ub2
out( base + index ) = arr2( index )
next
return out
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function Concat(Extends arr1() As String, arr2() As String) As String()
// Concatenate arr2 to arr1 and return the result as a new array.
Var out() As String
Var ub1 As Integer = arr1.LastIndex
Var ub2 As Integer = arr2.LastIndex
ReDim out( ub1 + ub2 + 1 )
Var index, base As Integer
for index = 0 to ub1
out( index ) = arr1( index )
next
base = ub1 + 1
for index = 0 to ub2
out( base + index ) = arr2( index )
next
return out
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function Max(Extends arr() As Double) As Double
// Return the greatest of the items in the array, or 0 for an empty array.
Var index, ub As Integer
Var out As Double
ub = arr.LastIndex
if ub >= 0 then
out = arr(0)
for index = 1 to ub
if arr(index) > out then out = arr(index)
next
end if
return out
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function Max(Extends arr() As Integer) As Integer
// Return the greatest of the items in the array, or 0 for an empty array.
Var index, ub As Integer
Var out As Integer
ub = arr.LastIndex
if ub >= 0 then
out = arr(0)
for index = 1 to ub
if arr(index) > out then out = arr(index)
next
end if
return out
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function Min(Extends arr() As Double) As Double
// Return the least of the items in the array, or 0 for an empty array.
Var index, ub As Integer
Var out As Double
ub = arr.LastIndex
if ub >= 0 then
out = arr(0)
for index = 1 to ub
if arr(index) < out then out = arr(index)
next
end if
return out
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function Min(Extends arr() As Integer) As Integer
// Return the least of the items in the array, or 0 for an empty array.
Var index, ub As Integer
Var out As Integer
ub = arr.LastIndex
if ub >= 0 then
out = arr(0)
for index = 1 to ub
if arr(index) < out then out = arr(index)
next
end if
return out
End Function
#tag EndMethod
#tag Method, Flags = &h0
Sub RemoveSlice(Extends arr() As Double, fromIndex As Integer = 0, toIndex As Integer = 0)
// Deletes a portion of the array.
// See "Slice Indexing" note.
Var ub As Integer = arr.LastIndex
if fromIndex < 0 then fromIndex = ub + 1 + fromIndex
if toIndex <= 0 then toIndex = ub + 1 + toIndex
if fromIndex > toIndex - 1 then return // empty (or invalid) range
// easy case: deleting the end of the array, we can just ReDim and be done
if toIndex - 1 = ub then
arr.ResizeTo( fromIndex - 1 )
return
end if
// another easy case: deleting just one element (equivalent to Arary.Remove)
if fromIndex = toIndex - 1 then
arr.RemoveAt( fromIndex )
return
end if
// harder case: copy the data down, and THEN redim
Var dest, src As Integer
dest = fromIndex
for src = toIndex to ub
arr(dest) = arr(src)
dest = dest + 1
next
arr.ResizeTo( dest - 1 )
return
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub RemoveSlice(Extends arr() As Integer, fromIndex As Integer = 0, toIndex As Integer = 0)
// Deletes a portion of the array.
// See "Slice Indexing" note.
Var ub As Integer = arr.LastIndex
if fromIndex < 0 then fromIndex = ub + 1 + fromIndex
if toIndex <= 0 then toIndex = ub + 1 + toIndex
if fromIndex >= toIndex then return // empty (or invalid) range
// easy case: deleting the end of the array, we can just ReDim and be done
if toIndex - 1 = ub then
arr.ResizeTo( fromIndex - 1 )
return
end if
// another easy case: deleting just one element (equivalent to Array.Remove)
if fromIndex = toIndex - 1 then
arr.RemoveAt( fromIndex )
return
end if
// harder case: copy the data down, and THEN redim
Var dest, src As Integer
dest = fromIndex
for src = toIndex to ub
arr(dest) = arr(src)
dest = dest + 1
next
arr.ResizeTo( dest - 1 )
return
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub RemoveSlice(Extends arr() As String, fromIndex As Integer = 0, toIndex As Integer = 0)
// Deletes a portion of the array.
// See "Slice Indexing" note.
Var ub As Integer = arr.LastIndex
if fromIndex < 0 then fromIndex = ub + 1 + fromIndex
if toIndex <= 0 then toIndex = ub + 1 + toIndex
if fromIndex > toIndex - 1 then return // empty (or invalid) range
// easy case: deleting the end of the array, we can just ReDim and be done
if toIndex -1 = ub then
arr.ResizeTo( fromIndex - 1 )
return
end if
// another easy case: deleting just one element (equivalent to Arary.Remove)
if fromIndex = toIndex - 1 then
arr.RemoveAt( fromIndex )
return
end if
// harder case: copy the data down, and THEN redim
Var dest, src As Integer
dest = fromIndex
for src = toIndex to ub
arr(dest) = arr(src)
dest = dest + 1
next
arr.ResizeTo( dest - 1 )
return
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub Reverse(Extends arr() As Double)
// Reverse the order of the elements in the array, in place.
Var low, high, midpoint As Integer
high = arr.LastIndex
if high < 1 then return
midpoint = (high + 1) \ 2
while low < midpoint
Var temp As Double = arr(low)
arr(low) = arr(high)
arr(high) = temp
low = low + 1
high = high - 1
wend
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub Reverse(Extends arr() As Integer)
// Reverse the order of the elements in the array, in place.
Var low, high, midpoint As Integer
high = arr.LastIndex
if high < 1 then return
midpoint = (high + 1) \ 2
while low < midpoint
Var temp As Integer = arr(low)
arr(low) = arr(high)
arr(high) = temp
low = low + 1
high = high - 1
wend
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub Reverse(Extends arr() As String)
// Reverse the order of the elements in the array, in place.
Var low, high, midpoint As Integer
high = arr.LastIndex
if high < 1 then return
midpoint = (high + 1) \ 2
while low < midpoint
Var temp As String = arr(low)
arr(low) = arr(high)
arr(high) = temp
low = low + 1
high = high - 1
wend
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Function Slice(Extends arr() As Double, fromIndex As Integer = 0, toIndex As Integer = 0) As Double()
// Return a subset of the given array.
// See "Slice Indexing" note.
// Note that if fromIndex and toIndex span the entire array, then
// this function is equivalent to Clone.
Var ub As Integer = arr.LastIndex
if fromIndex < 0 then fromIndex = ub + 1 + fromIndex
if toIndex <= 0 then toIndex = ub + 1 + toIndex
Var out() As Double
Var outbound As Integer = toIndex - fromIndex - 1
ReDim out( outbound )
Var index As Integer
for index = 0 to outbound
out( index ) = arr( fromIndex + index )
next
return out
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function Slice(Extends arr() As Integer, fromIndex As Integer = 0, toIndex As Integer = 0) As Integer()
// Return a subset of the given array.
// See "Slice Indexing" note.
// Note that if fromIndex and toIndex span the entire array, then
// this function is equivalent to Clone.
Var ub As Integer = arr.LastIndex
if fromIndex < 0 then fromIndex = ub + 1 + fromIndex
if toIndex <= 0 then toIndex = ub + 1 + toIndex
Var out() As Integer
Var outbound As Integer = toIndex - fromIndex - 1
ReDim out( outbound )
Var index As Integer
for index = 0 to outbound
out( index ) = arr( fromIndex + index )
next
return out
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function Slice(Extends arr() As String, fromIndex As Integer = 0, toIndex As Integer = 0) As String()
// Return a subset of the given array.
// See "Slice Indexing" note.
// Note that if fromIndex and toIndex span the entire array, then
// this function is equivalent to Clone.
Var ub As Integer = arr.LastIndex
if fromIndex < 0 then fromIndex = ub + 1 + fromIndex
if toIndex <= 0 then toIndex = ub + 1 + toIndex
Var out() As String
Var outbound As Integer = toIndex - fromIndex - 1
ReDim out( outbound )
Var index As Integer
for index = 0 to outbound
out( index ) = arr( fromIndex + index )
next
return out
End Function
#tag EndMethod
#tag Method, Flags = &h0
Sub Splice(Extends arr() As Double, fromIndex As Integer, toIndex As Integer, arrayToInsert() As Double, srcFrom As Integer = 0, srcTo As Integer = 0)
// This function replaces a section (or slice) of the base array with the contents
// of another array. The range replaced is specified with from/to indices, which
// may be negative, in which case they count from the end of the array (just as
// with the Slice method). The data to insert comes from arrayToInsert, and is
// specified in the same way -- by default, this is the entire source array.
Var ub As Integer = arr.LastIndex
if fromIndex < 0 then fromIndex = ub + 1 + fromIndex
if toIndex <= 0 then toIndex = ub + 1 + toIndex
Var srcub As Integer = arrayToInsert.LastIndex
if srcFrom < 0 then srcFrom = srcub + 1 + srcFrom
if srcTo <= 0 then srcTo = srcub + 1 + srcTo
// First, see whether we need to insert or remove items to make room.
Var qtyRemoving As Integer = toIndex - fromIndex
if qtyRemoving < 0 then return
Var qtyInserting As Integer = srcTo - srcFrom
if qtyInserting < 0 then qtyInserting = 0 // this is OK, just removes the dest slice
Var roomNeeded As Integer = qtyInserting - qtyRemoving
// Use RemoveSlice to remove any extra space.
if roomNeeded < 0 then
arr.RemoveSlice fromIndex, fromIndex - roomNeeded
end if
// Replace or insert values as needed.
Var srcPos, destPos As Integer
destPos = fromIndex
for srcPos = srcFrom to srcTo - 1
if destPos < toIndex then
arr(destPos) = arrayToInsert( srcPos )
else
arr.AddAt( destPos, arrayToInsert( srcPos ) )
end if
destPos = destPos + 1
next
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub Splice(Extends arr() As Integer, fromIndex As Integer, toIndex As Integer, arrayToInsert() As Integer, srcFrom As Integer = 0, srcTo As Integer = 0)
// This function replaces a section (or slice) of the base array with the contents
// of another array. The range replaced is specified with from/to indices, which
// may be negative, in which case they count from the end of the array (just as
// with the Slice method). The data to insert comes from arrayToInsert, and is
// specified in the same way -- by default, this is the entire source array.
Var ub As Integer = arr.LastIndex
if fromIndex < 0 then fromIndex = ub + 1 + fromIndex
if toIndex <= 0 then toIndex = ub + 1 + toIndex
Var srcub As Integer = arrayToInsert.LastIndex
if srcFrom < 0 then srcFrom = srcub + 1 + srcFrom
if srcTo <= 0 then srcTo = srcub + 1 + srcTo
// First, see whether we need to insert or remove items to make room.
Var qtyRemoving As Integer = toIndex - fromIndex
if qtyRemoving < 0 then return
Var qtyInserting As Integer = srcTo - srcFrom
if qtyInserting < 0 then qtyInserting = 0 // this is OK, just removes the dest slice
Var roomNeeded As Integer = qtyInserting - qtyRemoving
// Use RemoveSlice to remove any extra space.
if roomNeeded < 0 then
arr.RemoveSlice fromIndex, fromIndex - roomNeeded
end if
// Replace or insert values as needed.
Var srcPos, destPos As Integer
destPos = fromIndex
for srcPos = srcFrom to srcTo - 1
if destPos < toIndex then
arr(destPos) = arrayToInsert( srcPos )
else
arr.AddAt( destPos, arrayToInsert( srcPos ) )
end if
destPos = destPos + 1
next
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub Splice(Extends arr() As String, fromIndex As Integer, toIndex As Integer, arrayToInsert() As String, srcFrom As Integer = 0, srcTo As Integer = 0)
// This function replaces a section (or slice) of the base array with the contents
// of another array. The range replaced is specified with from/to indices, which
// may be negative, in which case they count from the end of the array (just as
// with the Slice method). The data to insert comes from arrayToInsert, and is
// specified in the same way -- by default, this is the entire source array.
Var ub As Integer = arr.LastIndex
if fromIndex < 0 then fromIndex = ub + 1 + fromIndex
if toIndex <= 0 then toIndex = ub + 1 + toIndex
Var srcub As Integer = arrayToInsert.LastIndex
if srcFrom < 0 then srcFrom = srcub + 1 + srcFrom
if srcTo <= 0 then srcTo = srcub + 1 + srcTo
// First, see whether we need to insert or remove items to make room.
Var qtyRemoving As Integer = toIndex - fromIndex
if qtyRemoving < 0 then return
Var qtyInserting As Integer = srcTo - srcFrom
if qtyInserting < 0 then qtyInserting = 0 // this is OK, just removes the dest slice
Var roomNeeded As Integer = qtyInserting - qtyRemoving
// Use RemoveSlice to remove any extra space.
if roomNeeded < 0 then
arr.RemoveSlice fromIndex, fromIndex - roomNeeded
end if
// Replace or insert values as needed.
Var srcPos, destPos As Integer
destPos = fromIndex
for srcPos = srcFrom to srcTo - 1
if destPos < toIndex then
arr(destPos) = arrayToInsert( srcPos )
else
arr.AddAt( destPos, arrayToInsert( srcPos ) )
end if
destPos = destPos + 1
next
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Function Total(Extends arr() As Double) As Double
// Return the total sum of the items in the array.
Var item, out As Double
for each item in arr
out = out + item
next
return out
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function Total(Extends arr() As Integer) As Integer
// Return the total sum of the items in the array.
Var item, out As Integer
for each item in arr
out = out + item
next
return out
End Function
#tag EndMethod
#tag Note, Name = Change History
2006-JAN-03:
- Initial release.
2006-JAN-16:
- Changed the meaning of the second slice index on Slice and RemoveSlice,
since careful thought about Splice pointed out how the previous meaning was wrong
and Guido van Rossum, as usual, was quite right. See "Slice Indexing" note.
- Renamed AppendArray to Append (this works fine as of RB2006R1).
- Finished the Splice and Append methods.
2006-JAN-31:
- Added the Concat method.
- Added the Reverse method.
2020-DEC-27:
- Renamed Append to Add
- Conversion to API2
2020-DEC-29:
- Feedback from Robert Livingston implemented:
"arr.LastIndex + 1" replaced by "arr.count"
"ReDim arr()" replaced by "arr.ResizeTo()"
#tag EndNote
#tag Note, Name = Contributors
Many people have contributed to the development of this module, including:
Joe Strout, joe@strout.net
Jeannot Muller, dr@jeannot-muller.com (*)
Robert Livingston
(*) To whom correspondence should be addressed.
#tag EndNote
#tag Note, Name = Home Page
This StringUtils module in the API Version 2 is maintained by TECcompanion GmbH.
The current administrative contact for it is Jeannot Muller (jeannot-muller.com).
You should be able to find the latest version via this URL:
https://jeannot-muller.com/
and on GitHub:
https://github.com/Jeannot-Muller/Xojo-ArrayUtils-API2
#tag EndNote
#tag Note, Name = License
This StringUtils module is in the public domain. You may use it for any purpose
whatsoever, but it comes with no express or implied warranty of correctness or
fitness for any purpose.
Share and enjoy!
#tag EndNote
#tag Note, Name = Slice Indexing
Several of the methods in this module take two indexes to specify a subset
off an array. Such a subset is called a "slice" and is involved in methods
such as RemoveSlice, Slice, and Splice.
In such cases, the first index specifies the first element in the slice. It may
be either an ordinary, non-negative index, in which case 0 means the first
element of the array, 1 means the second element, and so on. Or it may be
a negative number, in which case we count from the end of the array; -1 is
the last element, -2 is the next-to-last, and so on.
The second index specifies the element AFTER the last one to be included
in the slice. Again this may be positive or negative, but 0 in this case means
one past the end of the array.
This indexing scheme seems a bit odd at first (unless you are familiar with
Python), but it has a lot of advantages. Suppose you have an array 'a' with
five elements. Then you have:
a.Slice(0,0) is the entire array
a.Slice(0,-1) is all but the last element
a.Slice(1,0) is all but the first element
a.Slice(0,2) is the first two elements
a.Slice(2,0) is everything except the first two elements
Indeed, you can generalize and note that a.Slice(0,n).Concat( a.Slice(n,0) )
always comes out equal to n. Another advantage is that if you have a loop,
where either the first index is counting down to 0 or the last index is
counting up (from negative numbers) to 0, it will do the right thing in the
boundary cases (i.e. when the counter hits 0).
#tag EndNote
#tag ViewBehavior
#tag ViewProperty
Name="Name"
Visible=true
Group="ID"
InitialValue=""
Type="String"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Index"
Visible=true
Group="ID"
InitialValue="-2147483648"
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Super"
Visible=true
Group="ID"
InitialValue=""
Type="String"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Left"
Visible=true
Group="Position"
InitialValue="0"
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Top"
Visible=true
Group="Position"
InitialValue="0"
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag EndViewBehavior
End Module
#tag EndModule