Skip to content

Commit

Permalink
Merge pull request #1242 from primo-ppcg/reverse
Browse files Browse the repository at this point in the history
Rework `reverse`
  • Loading branch information
bakpakin authored Aug 6, 2023
2 parents 06eea74 + c8c0e11 commit 0ea1da8
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/boot/boot.janet
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0ea1da8

Please sign in to comment.