From 830b982357e215e8bc89bd572acd96327100d486 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 11 Jan 2021 14:56:17 -0500 Subject: [PATCH] Fixed most issues with the last pr --- src/AdvancedSet.ts | 10 ++++++++++ src/__tests__/MaxMin.test.ts | 14 ++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/__tests__/MaxMin.test.ts diff --git a/src/AdvancedSet.ts b/src/AdvancedSet.ts index 28c59f2..62be30e 100644 --- a/src/AdvancedSet.ts +++ b/src/AdvancedSet.ts @@ -152,6 +152,16 @@ export default class AdvancedSet { return this.toArray().every(test); } + public max(): number { + let arrSet = (this.toArray() as unknown[]) as number[]; + return Math.max(...arrSet); + } + + public min(): number { + let arrSet = (this.toArray() as unknown[]) as number[]; + return Math.min(...arrSet); + } + // partialSubset, isProperSubsetOf, isProperSupersetOf, multi set intersection, // power sets, subset by function } diff --git a/src/__tests__/MaxMin.test.ts b/src/__tests__/MaxMin.test.ts new file mode 100644 index 0000000..0e14ee2 --- /dev/null +++ b/src/__tests__/MaxMin.test.ts @@ -0,0 +1,14 @@ +import AdvancedSet from '../AdvancedSet'; + +test('Return the max value in the array', () => { + expect(new AdvancedSet(1, 3, 5).max()).toBe(5); +}); + + +test('Return the min value in the array', () => { + expect(new AdvancedSet(1, 3, 5).min()).toBe(1); +}); + +test('pass array of nulls', () => { + expect(new AdvancedSet(null, null, null).max()).toBe(0); +}) \ No newline at end of file