Skip to content

Commit ec3ee2b

Browse files
committed
Add Ruby snippet for calculating factorial
1 parent 3807b5c commit ec3ee2b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: Calculate Factorial
3+
description: Computes the factorial of a given integer.
4+
author: ACR1209
5+
tags: ruby,math,factorial
6+
---
7+
8+
```rb
9+
def factorial(n)
10+
return 1 if n <= 1
11+
(2..n).reduce(1, :*)
12+
end
13+
14+
# Usage:
15+
puts factorial(5) # Output: 120
16+
```

0 commit comments

Comments
 (0)