1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-01 04:19:55 +00:00

rework reverse

This commit is contained in:
primo-ppcg 2023-08-06 16:12:47 +07:00
parent ecc4d80a5a
commit c8c0e112bc

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