From c8aa490fee7c86c3a7c7e922d075e08836ab87a2 Mon Sep 17 00:00:00 2001 From: Tobias Mock Date: Mon, 9 Sep 2024 20:15:46 +0200 Subject: [PATCH] Add `reverse` function to array module --- std/array.smu | 7 +++++++ std/prelude.smu | 1 + 2 files changed, 8 insertions(+) diff --git a/std/array.smu b/std/array.smu index 8ba63a18..f41ff889 100644 --- a/std/array.smu +++ b/std/array.smu @@ -132,6 +132,13 @@ fun reserve(arr&, size) { } } +fun reverse(arr&) { + let length = length(arr) + iter_range(0, length / 2, fun i { + swap_items(&arr, i, length - i - 1) + }) +} + module fixed { let get = __fixed_array_get let length = __fixed_array_length diff --git a/std/prelude.smu b/std/prelude.smu index 77d177d4..c3f941cc 100644 --- a/std/prelude.smu +++ b/std/prelude.smu @@ -2,6 +2,7 @@ let + = __addi let - = __subi let * = __multi +let / = __divi let /. = __divf let < = __lessi let <= = __lesseqi