Skip to content

Commit ccd0133

Browse files
darkdrag00nv2j1010001nialexsan
authored
Document Reverse in Fixed/Variable sized Array (#169)
Co-authored-by: Jan Bernatik <[email protected]> Co-authored-by: Alex <[email protected]>
1 parent 2e0f907 commit ccd0133

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

docs/cadence/language/values-and-types.mdx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,36 @@ are available for both variable-sized and fixed-sized or variable-sized arrays.
12161216
let invalidIndices = example.slice(from: 2, upTo: 1)
12171217
```
12181218

1219+
-
1220+
```cadence
1221+
fun reverse(): [T]
1222+
```
1223+
1224+
Returns a new array with contents in the reversed order.
1225+
Available if `T` is not resource-kinded.
1226+
1227+
```cadence
1228+
let example = [1, 2, 3, 4]
1229+
1230+
// Create a new array which is the reverse of the original array.
1231+
let reversedExample = example.reverse()
1232+
// `reversedExample` is now `[4, 3, 2, 1]`
1233+
```
1234+
1235+
```cadence
1236+
fun reverse(): [T; N]
1237+
```
1238+
1239+
Returns a new fixed-sized array of same size with contents in the reversed order.
1240+
1241+
```cadence
1242+
let fixedSizedExample: [String; 3] = ["ABC", "XYZ", "PQR"]
1243+
1244+
// Create a new array which is the reverse of the original array.
1245+
let fixedArrayReversedExample = fixedSizedExample.reverse()
1246+
// `fixedArrayReversedExample` is now `["PQR", "XYZ", "ABC"]`
1247+
```
1248+
12191249
#### Variable-size Array Functions
12201250

12211251
The following functions can only be used on variable-sized arrays.

0 commit comments

Comments
 (0)