Improve recursive-reverse

This commit is contained in:
Kenneth Kostresevic 2021-12-17 13:02:05 +01:00
parent cdd46053a9
commit 4bd3bc9a72

View file

@ -14,10 +14,10 @@
(recur (dec n) (not acc)))))
(defn recursive-reverse [coll]
(loop [coll coll acc '()]
(if (= coll [])
acc
(recur (rest coll) (conj acc (first coll))))))
(loop [[head & tail] coll new-coll '()]
(if-not head
new-coll
(recur tail (conj new-coll head)))))
(defn factorial [n]
(loop [n n acc n]