Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added min and max functions #13 fixed #15

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fixed most issues with the last pr
  • Loading branch information
joey2031 committed Jan 11, 2021
commit 830b982357e215e8bc89bd572acd96327100d486
10 changes: 10 additions & 0 deletions src/AdvancedSet.ts
Original file line number Diff line number Diff line change
@@ -152,6 +152,16 @@ export default class AdvancedSet<T> {
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
}
14 changes: 14 additions & 0 deletions src/__tests__/MaxMin.test.ts
Original file line number Diff line number Diff line change
@@ -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);
})