Avoid extra decrementation in factorial
This commit is contained in:
parent
4bd3bc9a72
commit
807e32abbb
1 changed files with 2 additions and 2 deletions
|
|
@ -20,10 +20,10 @@
|
|||
(recur tail (conj new-coll head)))))
|
||||
|
||||
(defn factorial [n]
|
||||
(loop [n n acc n]
|
||||
(loop [n n acc 1]
|
||||
(if (= n 1)
|
||||
acc
|
||||
(recur (dec n) (* acc (dec n))))))
|
||||
(recur (dec n) (* acc n)))))
|
||||
|
||||
(meditations
|
||||
"Recursion ends with a base case"
|
||||
|
|
|
|||
Loading…
Reference in a new issue