1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-28 19:19:53 +00:00

Merge pull request #1242 from primo-ppcg/reverse

Rework `reverse`
This commit is contained in:
Calvin Rose 2023-08-06 08:10:56 -05:00 committed by GitHub
commit 0ea1da80e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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