London | 26-ITP-May | Vitalii Kmit | Sprint 1 | Exercises - #1458
Open
Vitalii-code wants to merge 8 commits into
Open
London | 26-ITP-May | Vitalii Kmit | Sprint 1 | Exercises#1458Vitalii-code wants to merge 8 commits into
Vitalii-code wants to merge 8 commits into
Conversation
Khantdotcom
suggested changes
Aug 24, 2026
Khantdotcom
left a comment
There was a problem hiding this comment.
- Fix median logic
- Look up what if you don't declare "const" in "for loop"
- Improved data structure of dedupe(list)
| list = list.filter((item) => typeof item === "number"); | ||
| list.sort((a, b) => a - b); | ||
|
|
||
| if (list.length <= 1) { |
There was a problem hiding this comment.
If an array has exactly one number (e.g., [5]), what is the median?
Comment on lines
+4
to
+5
| // for (let index = 0; index < list.length; index++) { | ||
| for (const element of list) { |
There was a problem hiding this comment.
Good job noticing a better approach for looping!
Comment on lines
+1
to
+13
| function dedupe(list) { | ||
| const seen = {}; | ||
| const result = []; | ||
|
|
||
| for (const item of list) { | ||
| if (seen[item] === undefined) { | ||
| seen[item] = true; | ||
| result.push(item); | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } |
There was a problem hiding this comment.
Good practice but there's a better data structure than simple dict and array. Check out this article here.
| function findMax(elements) { | ||
| let max = -Infinity; | ||
|
|
||
| for (i of elements) { |
There was a problem hiding this comment.
Can you look up what happens you don't declare "const" in for loop in javascript? Hint : related to "scope" of code blocks
| function sum(elements) { | ||
| let sum = 0; | ||
|
|
||
| for (i of elements) { |
There was a problem hiding this comment.
The program can run but why do we need "for (const i of elements)"?
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
Work on sprint one exercises