From 9fcbda1ba41f3f0eef749a1d299d736a66b76c3b Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Thu, 24 Sep 2020 10:51:21 +0800 Subject: [PATCH] Add reverse function to arrays. --- doc/src/language/arrays.md | 1 + src/packages/array_basic.rs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/doc/src/language/arrays.md b/doc/src/language/arrays.md index 2e1b8cc9..1f60decb 100644 --- a/doc/src/language/arrays.md +++ b/doc/src/language/arrays.md @@ -41,6 +41,7 @@ The following methods (mostly defined in the [`BasicArrayPackage`][packages] but | `pop` | _none_ | removes the last element and returns it ([`()`] if empty) | | `shift` | _none_ | removes the first element and returns it ([`()`] if empty) | | `remove` | index | removes an element at a particular index and returns it, or returns [`()`] if the index is not valid | +| `reverse` | _none_ | reverses the array | | `len` method and property | _none_ | returns the number of elements | | `pad` | element to pad, target length | pads the array with an element to at least a specified length | | `clear` | _none_ | empties the array | diff --git a/src/packages/array_basic.rs b/src/packages/array_basic.rs index 8b56be54..1647a156 100644 --- a/src/packages/array_basic.rs +++ b/src/packages/array_basic.rs @@ -133,6 +133,10 @@ mod array_functions { list.clear(); } } + #[inline(always)] + pub fn reverse(list: &mut Array) { + list.reverse(); + } } fn pad(