From 4bd3bc9a72efcb8a219fb43f4e3349cd46e838a1 Mon Sep 17 00:00:00 2001 From: Kenneth Kostresevic Date: Fri, 17 Dec 2021 13:02:05 +0100 Subject: [PATCH] Improve recursive-reverse --- src/koans/14_recursion.clj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/koans/14_recursion.clj b/src/koans/14_recursion.clj index d108809..5e05015 100644 --- a/src/koans/14_recursion.clj +++ b/src/koans/14_recursion.clj @@ -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]