Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc5b12db

Browse files
SpiderMathactions-userappgurueu
authored
feat: Added Double Factorial Iterative Implementation (#187)
* Update DIRECTORY.md* 🚀feat: added double factorial (iterative)* Update DIRECTORY.md* removed redundant if check, fix formatting* Update DIRECTORY.md---------Co-authored-by: autoprettier <actions@github.com>Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com>
1 parent26ac72d commitc5b12db

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

‎DIRECTORY.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
*[Calculate Median](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/calculate_median.ts)
109109
*[Degrees To Radians](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/degrees_to_radians.ts)
110110
*[Digit Sum](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/digit_sum.ts)
111+
*[Double Factorial Iterative](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/double_factorial_iterative.ts)
111112
*[Euler Totient](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/euler_totient.ts)
112113
*[Factorial](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/factorial.ts)
113114
*[Factors](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/factors.ts)
@@ -128,6 +129,7 @@
128129
*[Number Of Digits](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/number_of_digits.ts)
129130
*[Pascals Triangle](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/pascals_triangle.ts)
130131
*[Perfect Cube](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/perfect_cube.ts)
132+
*[Perfect Number](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/perfect_number.ts)
131133
*[Perfect Square](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/perfect_square.ts)
132134
*[Prime Factorization](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/prime_factorization.ts)
133135
*[Primes](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/primes.ts)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
*@function DoubleFactorialIterative
3+
*@description Calculate the double factorial of a number (iterative implementation)
4+
*@summary In mathematics, double factorial of a number n is denoted by n!!.
5+
* It is not to be confused with (n!)!, which is the factorial function iterated twice.
6+
* The double factorial is the product of all positive integers upto n that have the same parity (odd or even)
7+
* as n.
8+
* Therefore,
9+
* 9!! = 9 . 7 . 5 . 3 . 1
10+
* 10!! = 10 . 8 . 6 . 4 . 2
11+
*
12+
* Please note that for factorials of even numbers, the series ends at 2.
13+
*@see [Wikipedia](https://en.wikipedia.org/wiki/Double_factorial)
14+
*@see [Mathworld](https://mathworld.wolfram.com/DoubleFactorial.html)
15+
*@see [GeeksForGeeks](https://www.geeksforgeeks.org/double-factorial/)
16+
*@example DoubleFactorialIterative(4) = 8
17+
*@example DoubleFactorialIterative(5) = 15
18+
*/
19+
constDoubleFactorialIterative=(n:number)=>{
20+
if(n<0)thrownewRangeError("The number needs to be non-negative")
21+
letdoubleFactorial=1
22+
23+
for(leti=n;i>0;i-=2)
24+
doubleFactorial*=i
25+
26+
returndoubleFactorial
27+
}
28+
29+
export{DoubleFactorialIterative}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import{DoubleFactorialIterative}from"../double_factorial_iterative";
2+
3+
describe("Double Factorial",()=>{
4+
test.each([[4,8],[5,15],[10,3840]])("%i!! = %i",(n,expected)=>{
5+
expect(DoubleFactorialIterative(n)).toBe(expected)
6+
})
7+
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp