Skip to content

Commit

Permalink
Adding min
Browse files Browse the repository at this point in the history
  • Loading branch information
kamaal111 committed Apr 21, 2024
1 parent 2a14060 commit feaf542
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/maths/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './sum';
export * from './min';
18 changes: 18 additions & 0 deletions src/maths/min.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import min from './min';

describe('min', () => {
it('returns the minimum number', () => {
const result = min([2, 1, 3]);
expect(result).toEqual(1);
});

it('returns 1 of the minimum number', () => {
const result = min([2, 1, 1]);
expect(result).toEqual(1);
});

it('defaults to null when no values are passed in', () => {
const result = min([]);
expect(result).toBeNull();
});
});
6 changes: 6 additions & 0 deletions src/maths/min.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const min = (array: number[]): number | null => {
if (array.length === 0) return null;
return Math.min(...array);
};

export default min;

0 comments on commit feaf542

Please sign in to comment.