Skip to content

Commit

Permalink
Document Reverse in Fixed/Variable sized Array (#169)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan Bernatik <[email protected]>
Co-authored-by: Alex <[email protected]>
  • Loading branch information
3 people authored Jul 26, 2023
1 parent 2e0f907 commit ccd0133
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions docs/cadence/language/values-and-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,36 @@ are available for both variable-sized and fixed-sized or variable-sized arrays.
let invalidIndices = example.slice(from: 2, upTo: 1)
```

-
```cadence
fun reverse(): [T]
```

Returns a new array with contents in the reversed order.
Available if `T` is not resource-kinded.

```cadence
let example = [1, 2, 3, 4]
// Create a new array which is the reverse of the original array.
let reversedExample = example.reverse()
// `reversedExample` is now `[4, 3, 2, 1]`
```

```cadence
fun reverse(): [T; N]
```

Returns a new fixed-sized array of same size with contents in the reversed order.

```cadence
let fixedSizedExample: [String; 3] = ["ABC", "XYZ", "PQR"]

// Create a new array which is the reverse of the original array.
let fixedArrayReversedExample = fixedSizedExample.reverse()
// `fixedArrayReversedExample` is now `["PQR", "XYZ", "ABC"]`
```

#### Variable-size Array Functions

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

1 comment on commit ccd0133

@vercel
Copy link

@vercel vercel bot commented on ccd0133 Jul 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.