-
-
Notifications
You must be signed in to change notification settings - Fork 283
Manchester | 26-ITP-Jan | Liban Jama | Sprint 1 | Data Groups #1016
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
Open
libanj0161
wants to merge
15
commits into
CodeYourFuture:main
Choose a base branch
from
libanj0161:Module-Data-Groups-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
152abe7
completed median sprint 1
libanj0161 7bc29b0
completed implement
libanj0161 9f5cc0a
Completed includes.js
libanj0161 c6cb7b0
Merge branch 'Module-Data-Groups-1-implement' into Module-Data-Groups…
libanj0161 69bd5cb
Merge branch 'Module-Data-Groups-1-refactor' into Module-Data-Groups-fix
libanj0161 dca5a95
used .filter and isFinite
libanj0161 a4668aa
added isFinite check to sum.js
libanj0161 560de00
Added isFinite to max.js
libanj0161 e6c96f7
Added tests
libanj0161 7d83b62
Added test for numeric string
libanj0161 32ffac4
updated test
libanj0161 cbfd6c4
updated test description
libanj0161 51192fc
updated test
libanj0161 aa9ddca
added test
libanj0161 44c82b2
combined tests
libanj0161 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,12 @@ | ||
| function dedupe() {} | ||
| function dedupe(elements) { | ||
| const result = []; | ||
| for (let i = 0; i < elements.length; i++) { | ||
| if (!result.includes(elements[i])) { | ||
| result.push(elements[i]); | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| module.exports = dedupe; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,20 @@ | ||
| function findMax(elements) { | ||
| } | ||
| const numbersOnly = elements.filter( | ||
| (e) => typeof e === "number" && Number.isFinite(e) | ||
| ); | ||
|
|
||
| if (numbersOnly.length === 0) { | ||
| return -Infinity; | ||
| } | ||
|
|
||
| let max = numbersOnly[0]; | ||
|
|
||
| for (let i = 1; i < numbersOnly.length; i++) { | ||
| if (numbersOnly[i] > max) { | ||
| max = numbersOnly[i]; | ||
| } | ||
| } | ||
|
|
||
| return max; | ||
| } | ||
| module.exports = findMax; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,28 +16,68 @@ const findMax = require("./max.js"); | |
| // When passed to the max function | ||
| // Then it should return -Infinity | ||
| // Delete this test.todo and replace it with a test. | ||
| test.todo("given an empty array, returns -Infinity"); | ||
| test("given an empty array, returns -Infinity", () => { | ||
| expect(findMax([])).toBe(-Infinity); | ||
| }); | ||
|
|
||
| // Given an array with one number | ||
| // When passed to the max function | ||
| // Then it should return that number | ||
|
|
||
| test("given an array with one number, returns that number", () => { | ||
| expect(findMax([7])).toBe(7); | ||
| }); | ||
|
|
||
| // Given an array with both positive and negative numbers | ||
| // When passed to the max function | ||
| // Then it should return the largest number overall | ||
|
|
||
| test("given positive and negative numbers, returns the largest number", () => { | ||
| expect(findMax([-3, 7, -2, 5])).toBe(7); | ||
| }); | ||
|
|
||
| // Given an array with just negative numbers | ||
| // When passed to the max function | ||
| // Then it should return the closest one to zero | ||
|
|
||
| test("given an array with only negative numbers, returns the closest to zero", () => { | ||
| expect(findMax([-10, -3, -7])).toBe(-3); | ||
| }); | ||
|
|
||
| // Given an array with decimal numbers | ||
| // When passed to the max function | ||
| // Then it should return the largest decimal number | ||
|
|
||
| test("given an array with decimal numbers, returns the clargest decimal number", () => { | ||
| expect(findMax([2.7, 6.9, 10.1])).toBe(10.1); | ||
| }); | ||
|
|
||
| // Given an array with non-number values | ||
| // When passed to the max function | ||
| // Then it should return the max and ignore non-numeric values | ||
|
|
||
| test("given an array with non-number values, returns the max and ignore non-numeric values", () => { | ||
| expect(findMax([3, "dogs", 1, "cat", null])).toBe(3); | ||
| }); | ||
|
|
||
| // Given an array with only non-number values | ||
| // When passed to the max function | ||
| // Then it should return the least surprising value given how it behaves for all other inputs | ||
|
|
||
| test("given an array with only non-number values, returns -Infinity", () => { | ||
| expect(findMax(["a", null, true, undefined])).toBe(-Infinity); | ||
| }); | ||
|
cjyuan marked this conversation as resolved.
|
||
|
|
||
| // Given an array with Nan | ||
| // When passed to the max function | ||
| // Then it should return the correct total | ||
| test("given an array including Nan return correct total", () => { | ||
| expect(findMax([11, NaN, 5])).toBe(11); | ||
| }); | ||
|
|
||
| // Given an array with numeric string value | ||
| // When passed to the max function | ||
| // Then it should ignore the numeric string and return correct total | ||
| test("given an array with numeric string value, it should ignore the numeric string and return correct total", () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The description of the expected return value are not quite correct.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated test description |
||
| expect(findMax([8, "14", 2])).toBe(8); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,12 @@ | ||
| function sum(elements) { | ||
| let total = 0; | ||
|
|
||
| for (let i = 0; i < elements.length; i++) { | ||
| if (typeof elements[i] === "number" && Number.isFinite(elements[i])) { | ||
| total += elements[i]; | ||
| } | ||
| } | ||
| return total; | ||
| } | ||
|
|
||
| module.exports = sum; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a chance that, even though
resulthas incorrect elements (for example,[]),the two tests could still pass. Can you figure out why, and then fix the tests accordingly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added .toHaveLength to ensure the returned array has the same number of elements as the original.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is better but it is still not 100% bullet proof. What if result is
["a", "b", "x"]?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the test to ensure
expectedhas the expected elements?And optionally add another test to ensure
inputremains unchanged after the function call.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my research .toEqual already ensures the returned array has the exact expected elements. I also added an additional test to verify that calling the function does not change the original array.