Skip to content

Commit 6a4744d

Browse files
committed
Fix max
1 parent c29e888 commit 6a4744d

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# deverything
22

3+
## 3.3.1
4+
5+
### Patch Changes
6+
7+
- max fix
8+
39
## 3.3.0
410

511
### Minor Changes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "deverything",
3-
"version": "3.3.0",
3+
"version": "3.3.1",
44
"description": "Everything you need for Dev",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",

src/math/max.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe, expect, test } from "@jest/globals";
2+
import { max } from "./max";
3+
4+
describe("max", () => {
5+
test("simple", async () => {
6+
expect(max([1, 2])).toBe(2);
7+
expect(max([-1, -12])).toBe(-1);
8+
expect(max([0])).toBe(0);
9+
expect(max([])).toBe(0);
10+
expect(max([-Infinity, 0])).toBe(0);
11+
});
12+
});

src/math/max.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
/**
2+
* Returns the maximum value in an array of numbers.
3+
* @param values - The array of numbers to find the maximum value of.
4+
* @returns The maximum value in the array. If the array is empty, returns 0.
5+
*/
16
export const max = (values: number[]): number => {
7+
if (!values.length) {
8+
return 0;
9+
}
210
const maxValue = Math.max(...values);
311
return maxValue;
412
};

0 commit comments

Comments
 (0)