Skip to content

Commit c79edd0

Browse files
committed
UtilityFunctions (DS) Documentation
1 parent d7703cf commit c79edd0

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

docs/utils/utilityFunctions.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# UtilityFunctions
2+
3+
The `UtilityFunctions` class contains static utility methods for performing common mathematical operations on arrays of numbers.
4+
5+
## Methods
6+
7+
### `sum(arr: number[]): number`
8+
9+
Calculates the sum of all the elements in the given array of numbers.
10+
11+
- `arr` (Array of Numbers): The array of numbers to calculate the sum for.
12+
13+
**Example:**
14+
15+
```javascript
16+
const numbers = [1, 2, 3, 4, 5];
17+
const sumResult = UtilityFunctions.sum(numbers); // Returns 15
18+
```
19+
20+
### `average(arr: number[]): number`
21+
22+
Calculates the average (mean) of all the elements in the given array of numbers.
23+
24+
- `arr` (Array of Numbers): The array of numbers to calculate the average for.
25+
26+
**Example:**
27+
28+
```javascript
29+
const numbers = [2, 4, 6, 8, 10];
30+
const averageResult = UtilityFunctions.average(numbers); // Returns 6
31+
```
32+
33+
## Testing
34+
35+
You can use the provided test cases to ensure the correctness of these utility functions. The test cases use the Jest testing framework.
36+
37+
### Running Tests
38+
39+
1. Make sure you have Jest installed (you can install it using `npm install jest`).
40+
2. Run the tests using the following command:
41+
42+
```bash
43+
npx jest
44+
```
45+
46+
## Conclusion
47+
48+
The `UtilityFunctions` class provides convenient methods for calculating the sum and average of an array of numbers. These methods are useful for a variety of scenarios in which you need to perform basic mathematical calculations on data sets.

0 commit comments

Comments
 (0)