From 9e3148a3d0cb9f6948a4ad03b926de82bfacb369 Mon Sep 17 00:00:00 2001 From: muhammadfahaddev Date: Sat, 20 Dec 2025 10:02:18 +0500 Subject: [PATCH 1/2] Improve console output formatting in Recursion glossary --- files/en-us/glossary/recursion/index.md | 27 ++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/files/en-us/glossary/recursion/index.md b/files/en-us/glossary/recursion/index.md index 83ced1da1133a81..a34aa4351756da3 100644 --- a/files/en-us/glossary/recursion/index.md +++ b/files/en-us/glossary/recursion/index.md @@ -55,6 +55,8 @@ console.log(getMaxCallStackSize(0)); ### Common usage examples +#### Factorial + ```js const factorial = (n) => { if (n === 0) { @@ -63,20 +65,39 @@ const factorial = (n) => { return n * factorial(n - 1); }; console.log(factorial(10)); -// 3628800 ``` +Output: + +```plain +3628800 +``` + +#### Fibonacci + ```js const fibonacci = (n) => (n <= 2 ? 1 : fibonacci(n - 1) + fibonacci(n - 2)); console.log(fibonacci(10)); -// 55 ``` +Output: + +```plain +55 +``` + +#### Reduce + ```js const reduce = (fn, acc, [cur, ...rest]) => cur === undefined ? acc : reduce(fn, fn(acc, cur), rest); console.log(reduce((a, b) => a + b, 0, [1, 2, 3, 4, 5, 6, 7, 8, 9])); -// 45 +``` + +Output: + +```plain +45 ``` ## See also From 35f5e3aa29525da9274cc6f0a1c6bc44d0d6440d Mon Sep 17 00:00:00 2001 From: Hamish Willee Date: Mon, 22 Dec 2025 11:41:36 +1100 Subject: [PATCH 2/2] Apply suggestions from code review --- files/en-us/glossary/recursion/index.md | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/files/en-us/glossary/recursion/index.md b/files/en-us/glossary/recursion/index.md index a34aa4351756da3..1c3053205dd3398 100644 --- a/files/en-us/glossary/recursion/index.md +++ b/files/en-us/glossary/recursion/index.md @@ -65,12 +65,7 @@ const factorial = (n) => { return n * factorial(n - 1); }; console.log(factorial(10)); -``` - -Output: - -```plain -3628800 +// 3628800 ``` #### Fibonacci @@ -78,12 +73,7 @@ Output: ```js const fibonacci = (n) => (n <= 2 ? 1 : fibonacci(n - 1) + fibonacci(n - 2)); console.log(fibonacci(10)); -``` - -Output: - -```plain -55 +// 55 ``` #### Reduce @@ -92,12 +82,7 @@ Output: const reduce = (fn, acc, [cur, ...rest]) => cur === undefined ? acc : reduce(fn, fn(acc, cur), rest); console.log(reduce((a, b) => a + b, 0, [1, 2, 3, 4, 5, 6, 7, 8, 9])); -``` - -Output: - -```plain -45 +// 45 ``` ## See also