London | ITP-MAY-25 | Surafel Workneh| Module: Data Groups | Sprint-1#681
Closed
SuWebOnes wants to merge 13 commits intoCodeYourFuture:mainfrom
Closed
London | ITP-MAY-25 | Surafel Workneh| Module: Data Groups | Sprint-1#681SuWebOnes wants to merge 13 commits intoCodeYourFuture:mainfrom
SuWebOnes wants to merge 13 commits intoCodeYourFuture:mainfrom
Conversation
…If no valid numbers, return null
…urn the middle plus
…t returns a copy of the original array
…ical element of an array
…numerical elements of an array
…ical elements of an array
a-robson
reviewed
Jul 29, 2025
a-robson
left a comment
There was a problem hiding this comment.
Excellent. Code quality is high and you are making great progress. I've made some comments and suggestions.
Comment on lines
+9
to
+10
| // Clone and sort the array numerically | ||
| const sorted = [...nums].sort((a, b) => a - b); |
There was a problem hiding this comment.
Overall this is excellent. But is it necessary to clone the array here? Could we just sort it?
Comment on lines
+1
to
+16
| function dedupe(arr) { | ||
| if (!Array.isArray(arr)) return []; | ||
|
|
||
| const seen = new Set(); | ||
| const result = []; | ||
|
|
||
| for (const item of arr) { | ||
| if (!seen.has(item)) { | ||
| seen.add(item); | ||
| result.push(item); | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
There was a problem hiding this comment.
Very good. Using a Set is the right approach. However there are easier ways in Javascript to populate a Set from an array. Do we need a for loop at all?
Comment on lines
1
to
7
| function sum(elements) { | ||
| if (!Array.isArray(elements)) return 0; | ||
|
|
||
| return elements.reduce((acc, val) => { | ||
| return typeof val === "number" && !isNaN(val) ? acc + val : acc; | ||
| }, 0); | ||
| } |
There was a problem hiding this comment.
Very good. However using filter() then reduce() is a more common approach to this type of problem. What are the advantages of using this pattern rather than having the 'filtering logic' within the reduce() function?
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
Briefly explain your PR.
Questions
Ask any questions you have for your reviewer.