From c8c0e112bcfebf490d6fd380396d464d6004018a Mon Sep 17 00:00:00 2001 From: primo-ppcg Date: Sun, 6 Aug 2023 16:12:47 +0700 Subject: [PATCH] rework `reverse` --- src/boot/boot.janet | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 46432619..9d997cb6 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -1450,12 +1450,10 @@ a new array. If a string or buffer is provided, returns an array of its byte values, reversed.` [t] - (def len (length t)) - (var n (- len 1)) - (def ret (array/new len)) - (while (>= n 0) - (array/push ret (in t n)) - (-- n)) + (var n (length t)) + (def ret (array/new-filled n)) + (forv i 0 n + (put ret i (in t (-- n)))) ret) (defn invert