From f0e5cc0f70ba08be34d7c9efe21077270db5e1c1 Mon Sep 17 00:00:00 2001 From: autoprettier Date: Fri, 6 Oct 2023 07:32:04 +0000 Subject: [PATCH 1/5] Update DIRECTORY.md --- DIRECTORY.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 3237c4e5..4d2eb199 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -9,9 +9,11 @@ ## Bit Manipulation * [Is Power Of 2](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/bit_manipulation/is_power_of_2.ts) * [Is Power Of 4](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/bit_manipulation/is_power_of_4.ts) + * [Log Two](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/bit_manipulation/log_two.ts) * Test * [Is Power Of 2.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/bit_manipulation/test/is_power_of_2.test.ts) * [Is Power Of 4.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/bit_manipulation/test/is_power_of_4.test.ts) + * [Log Two.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/bit_manipulation/test/log_two.test.ts) ## Ciphers * [Xor Cipher](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/ciphers/xor_cipher.ts) @@ -71,6 +73,7 @@ ## Dynamic Programming * [Knapsack](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/dynamic_programming/knapsack.ts) + * [Lcs](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/dynamic_programming/lcs.ts) ## Graph * [Bellman Ford](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/bellman_ford.ts) @@ -154,3 +157,4 @@ * [Quick Sort](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/sorts/quick_sort.ts) * [Selection Sort](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/sorts/selection_sort.ts) * [Shell Sort](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/sorts/shell_sort.ts) + * [Swap Sort](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/sorts/swap_sort.ts) From 3a89697084200ff8d14c342a65fa79fb5e56610b Mon Sep 17 00:00:00 2001 From: SpiderMath <71999854+SpiderMath@users.noreply.github.com> Date: Fri, 6 Oct 2023 13:42:49 +0530 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=9A=80feat:=20added=20double=20factor?= =?UTF-8?q?ial=20(iterative)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maths/double_factorial_iterative.ts | 30 +++++++++++++++++++ maths/test/double_factorial_iterative.test.ts | 7 +++++ 2 files changed, 37 insertions(+) create mode 100644 maths/double_factorial_iterative.ts create mode 100644 maths/test/double_factorial_iterative.test.ts diff --git a/maths/double_factorial_iterative.ts b/maths/double_factorial_iterative.ts new file mode 100644 index 00000000..93daf8aa --- /dev/null +++ b/maths/double_factorial_iterative.ts @@ -0,0 +1,30 @@ +/** + * @function DoubleFactorialIterative + * @description Calculate the double factorial of a number (iterative implementation) + * @summary In mathematics, double factorial of a number n is denoted by n!!. + * It is not to be confused with (n!)!, which is the factorial function iterated twice. + * The double factorial is the product of all positive integers upto n that have the same parity (odd or even) + * as n. + * Therefore, + * 9!! = 9 . 7 . 5 . 3 . 1 + * 10!! = 10 . 8 . 6 . 4 . 2 + * + * Please note that for factorials of even numbers, the series ends at 2. + * @see [Wikipedia](https://en.wikipedia.org/wiki/Double_factorial) + * @see [Mathworld](https://mathworld.wolfram.com/DoubleFactorial.html) + * @see [GeeksForGeeks](https://www.geeksforgeeks.org/double-factorial/) + * @example DoubleFactorialIterative(4) = 8 + * @example DoubleFactorialIterative(5) = 15 + */ +const DoubleFactorialIterative = (n: number) => { + if(n < 0) throw new RangeError("The number needs to be non-negative") + if(n === 0) return 1; + let doubleFactorial = 1; + + for(let i = n; i > 0; i -= 2) + doubleFactorial *= i; + + return doubleFactorial; +} + +export { DoubleFactorialIterative }; diff --git a/maths/test/double_factorial_iterative.test.ts b/maths/test/double_factorial_iterative.test.ts new file mode 100644 index 00000000..3c221785 --- /dev/null +++ b/maths/test/double_factorial_iterative.test.ts @@ -0,0 +1,7 @@ +import { DoubleFactorialIterative } from "../double_factorial_iterative"; + +describe("Double Factorial", () => { + test.each([[4, 8], [5, 15], [10, 3840]])("%i!! = %i", (n, expected) => { + expect(DoubleFactorialIterative(n)).toBe(expected) + }) +}) \ No newline at end of file From fdf5fbaeb2ea760ddfed032ebf4fade6e51896e1 Mon Sep 17 00:00:00 2001 From: autoprettier Date: Fri, 6 Oct 2023 08:13:14 +0000 Subject: [PATCH 3/5] Update DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 4d2eb199..f46c278b 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -100,6 +100,7 @@ * [Calculate Median](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/calculate_median.ts) * [Degrees To Radians](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/degrees_to_radians.ts) * [Digit Sum](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/digit_sum.ts) + * [Double Factorial Iterative](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/double_factorial_iterative.ts) * [Factorial](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/factorial.ts) * [Factors](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/factors.ts) * [Fibonacci](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/fibonacci.ts) From 8d3f5c309e5b93ecff52654edff1dfed0cec9597 Mon Sep 17 00:00:00 2001 From: The Defective Detective <71999854+SpiderMath@users.noreply.github.com> Date: Mon, 9 Oct 2023 21:51:32 +0530 Subject: [PATCH 4/5] removed redundant if check, fix formatting --- maths/double_factorial_iterative.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/maths/double_factorial_iterative.ts b/maths/double_factorial_iterative.ts index 93daf8aa..6044eca0 100644 --- a/maths/double_factorial_iterative.ts +++ b/maths/double_factorial_iterative.ts @@ -18,13 +18,12 @@ */ const DoubleFactorialIterative = (n: number) => { if(n < 0) throw new RangeError("The number needs to be non-negative") - if(n === 0) return 1; - let doubleFactorial = 1; + let doubleFactorial = 1 for(let i = n; i > 0; i -= 2) - doubleFactorial *= i; + doubleFactorial *= i - return doubleFactorial; + return doubleFactorial } -export { DoubleFactorialIterative }; +export { DoubleFactorialIterative } From 4c87609b73465717765b9ef7d51456799e534198 Mon Sep 17 00:00:00 2001 From: autoprettier Date: Tue, 5 Mar 2024 00:29:44 +0000 Subject: [PATCH 5/5] Update DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 8bcbfe4b..185bae95 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -129,6 +129,7 @@ * [Number Of Digits](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/number_of_digits.ts) * [Pascals Triangle](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/pascals_triangle.ts) * [Perfect Cube](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/perfect_cube.ts) + * [Perfect Number](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/perfect_number.ts) * [Perfect Square](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/perfect_square.ts) * [Prime Factorization](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/prime_factorization.ts) * [Primes](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/primes.ts)