From 70f1f2c3a06283a7877dd088d5ec491385183bed Mon Sep 17 00:00:00 2001 From: darkdrag00n Date: Mon, 24 Jul 2023 23:40:00 +0530 Subject: [PATCH] Document Reverse in Fixed/Variable sized Array --- docs/cadence/language/values-and-types.mdx | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/cadence/language/values-and-types.mdx b/docs/cadence/language/values-and-types.mdx index 470e8e5ae1..de30ce0499 100644 --- a/docs/cadence/language/values-and-types.mdx +++ b/docs/cadence/language/values-and-types.mdx @@ -1201,6 +1201,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.