Horje
Factorialize a Number (Tail Call Optimization) Code Example
Factorialize a Number (Tail Call Optimization)
// Factorialize a Number

function factorialize(num) {
	if (num === 0) return 1;
	return num * factorialize(num - 1);
}

factorialize(5);

// OR with Tail Call Optimization (https://stackoverflow.com/questions/33923/what-is-tail-recursion)

function factorialize(num, factorial = 1) {
	if (num == 0) {
		return factorial;
	} else {
		return factorialize(num - 1, factorial * num);
	}
}

factorialize(5);




Javascript

Related
bootstrap pop modal from another modal Code Example bootstrap pop modal from another modal Code Example
get only numbers from string Code Example get only numbers from string Code Example
jquery on scroll Code Example jquery on scroll Code Example
get random element from string array java Code Example get random element from string array java Code Example
price range slider bootstrap 4 Code Example price range slider bootstrap 4 Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8