generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 275
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 all 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,12 +16,31 @@ E.g. dedupe([1, 2, 1]) target output: [1, 2] | |
| // Given an empty array | ||
| // When passed to the dedupe function | ||
| // Then it should return an empty array | ||
| test.todo("given an empty array, it returns an empty array"); | ||
| test("given an empty array, it returns an empty array", () => { | ||
| expect(dedupe([])).toEqual([]); | ||
| }); | ||
|
|
||
| // Given an array with no duplicates | ||
| // When passed to the dedupe function | ||
| // Then it should return a copy of the original array | ||
| test("given an array with no duplicates, it should return a copy of the original array", () => { | ||
| const input = ["a", "b", "c"]; | ||
| const result = dedupe(input); | ||
|
|
||
| // Given an array with strings or numbers | ||
| expect(result).toHaveLength(input.length); | ||
| expect(result).toEqual(input); | ||
| expect(result).not.toBe(input); | ||
| }); | ||
cjyuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Given an array with strings | ||
| // When passed to the dedupe function | ||
| // Then it should remove the duplicate values, preserving the first occurence of each element | ||
| // Then it should remove duplicates and not modify the original array | ||
| test("given an array with strings, it should remove duplicates and preserve the original array", () => { | ||
| const input = ["a", "a", "a", "b", "b", "c"]; | ||
| const original = [...input]; | ||
|
|
||
| const result = dedupe(input); | ||
|
|
||
| expect(result).toEqual(["a", "b", "c"]); | ||
| expect(input).toEqual(original); | ||
|
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. You could combine this with the previous test.
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. I have now, thanks |
||
| }); | ||
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
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.