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