Skip to content

Commit

Permalink
Hotfix indexing (#25)
Browse files Browse the repository at this point in the history
fix indexing mistake
  • Loading branch information
joshring authored Aug 27, 2024
1 parent f5a9f48 commit 885ff32
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/content/docs/references/docs/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@ fn void test()
}
```

You can also use the `arr[<start index> : <slice length>]`
You can also use the `arr[<start-index> : <slice-length>]`
```c3
fn void test()
{
int[5] a = { 1, 20, 50, 100, 200 };
int[] b2 = a[0 : 5]; // { 1, 20, 50, 100, 200 } Start index 0, slice length 5
int[] c2 = a[1 : 2]; // { 50, 100 } Start index 2, slice length 2
int[] b2 = a[0 : 5]; // { 1, 20, 50, 100, 200 } start-index 0, slice-length 5
int[] c2 = a[1 : 2]; // { 50, 100 } start-index 2, slice-length 2
}
```

It’s possible to omit the first and last indices of a range:
- `arr[..<end-index>]` Omitting the start index will default it to 0
- `arr[<start-index>..]` Omitting the `end-index` will set `arr.len()` (this is not allowed on pointers)
- `arr[..<end-index>]` Omitting the `start-index` will default it to 0
- `arr[<start-index>..]` Omitting the `end-index` will assign it to `arr.len()-1` (this is not allowed on pointers)

Equivalently with index offset `arr[:<slice-length>]` you can omit the `start-index`

Expand Down Expand Up @@ -119,9 +119,9 @@ fn void test()
int[] b2 = a[1 .. ^2]; // { 20, 50, 100 } a[1 .. (len-2)]
int[] b3 = a[1 .. ^3]; // { 20, 50 } a[1 .. (len-3)]
int[] c1 = a[^1..]; // { 200 } a[(len-1)..]
int[] c2 = a[^2..]; // { 100, 200 } a[(len-2)..]
int[] c3 = a[^3..]; // { 50, 100, 200 } a[(len-3)..]
int[] c1 = a[^1..]; // { 200 } a[(len-1)..]
int[] c2 = a[^2..]; // { 100, 200 } a[(len-2)..]
int[] c3 = a[^3..]; // { 50, 100, 200 } a[(len-3)..]
int[] d = a[^3 : 2]; // { 50, 100 } a[(len-3) : 2]
Expand Down

0 comments on commit 885ff32

Please sign in to comment.