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))))) (recur (dec n) (not acc)))))
(defn recursive-reverse [coll] (defn recursive-reverse [coll]
(loop [coll coll acc '()] (loop [[head & tail] coll new-coll '()]
(if (= coll []) (if-not head
acc new-coll
(recur (rest coll) (conj acc (first coll)))))) (recur tail (conj new-coll head)))))
(defn factorial [n] (defn factorial [n]
(loop [n n acc n] (loop [n n acc n]