Improve recursive-reverse
This commit is contained in:
parent
cdd46053a9
commit
4bd3bc9a72
1 changed files with 4 additions and 4 deletions
|
|
@ -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]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue