From a906b7ed697c430e3c60bfc9290cb33155fadd91 Mon Sep 17 00:00:00 2001 From: Shashi3k <139968956+Shashi3k@users.noreply.github.com> Date: Sat, 26 Aug 2023 23:25:34 +0530 Subject: [PATCH] Added a recursive solution to factorial problem i added a recursive code under your iterative code. Please merge it to your code --- src/algorithms/math/factorial/factorial.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/algorithms/math/factorial/factorial.js b/src/algorithms/math/factorial/factorial.js index 6c717d05..1e8eb0a6 100644 --- a/src/algorithms/math/factorial/factorial.js +++ b/src/algorithms/math/factorial/factorial.js @@ -11,3 +11,16 @@ export default function factorial(number) { return result; } +/** + * @param {number} number + * @return {number} + * Recursive solution + */ +export default function factorial(number){ + if (number>=1){ + return number*factorial(number-1); + } + else{ + return 1 + } +}