Sheffield | 26-ITP-Jan | Mahammad Osman | Sprint 1 | Sprint-1#1074
Open
Darkidd77 wants to merge 12 commits intoCodeYourFuture:mainfrom
Open
Sheffield | 26-ITP-Jan | Mahammad Osman | Sprint 1 | Sprint-1#1074Darkidd77 wants to merge 12 commits intoCodeYourFuture:mainfrom
Darkidd77 wants to merge 12 commits intoCodeYourFuture:mainfrom
Conversation
…corresponding tests
…ios and edge cases
…ulate the sum of numbers
cjyuan
reviewed
Mar 24, 2026
…the input list to snap out `infinity`, `-infinity` and `NaN`
… and enhance readability
cjyuan
reviewed
Apr 3, 2026
Comment on lines
+27
to
+32
| test("should return a copy of the original array when there are no duplicates", () => { | ||
| const input = [1, 2, 3]; | ||
| expect(dedupe(input)).toEqual(input); | ||
|
|
||
| // Given an array of strings or numbers | ||
| // When passed to the dedupe function | ||
| // Then it should return a new array with duplicates removed while preserving the | ||
| // first occurrence of each element from the original array. | ||
| expect(dedupe(input)).not.toBe(input); | ||
| }); |
Contributor
There was a problem hiding this comment.
There is a chance that, even though the returned value has incorrect elements (for example, [1, 1, 1]),
the two tests could still pass. Can you figure out why, and then fix the tests accordingly?
Author
There was a problem hiding this comment.
Done! Yes, it's because this test could still pass even if the original array were destroyed or mutated in the function. It's a very interesting trap.
To fix it, I saved the output to a result variable and properly compared it against a hardcoded array. Thinking about TDD this deeply has been a great learning experience. Thank you
Contributor
|
All good! Well done. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Learners, PR Template
Self checklist
Changelist
dedupe.js: Implemented array deduplication logic.max.js: Refactored to use a functional pipeline (.filter()andMath.maxwith the spread operator...) to safely ignore NaN and non-numeric strings.sum.js: Implemented sum calculation using.reduce().includes.js: Fixed a premature return bug inside the loop so the function correctly evaluates the entire array before returning false.solution.js(Advent of Code): Built a data parsing pipeline usingfs.readFileSync,.split('\n'), and.map(Number)to process a text file and calculate a final total using.reduce().