GLASGOW | Jan-26-ITP | Prakash Dcosta | Sprint 1 | Data Groups#1005
GLASGOW | Jan-26-ITP | Prakash Dcosta | Sprint 1 | Data Groups#1005dcostaprakash wants to merge 3 commits intoCodeYourFuture:mainfrom
Conversation
Self checklist - [X] I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title - [X] My changes meet the requirements of the task - [X] I have tested my changes - [X] My changes follow the [style guide] ## Changelist In this PR, i have implemented functions according to requrements and built test cases
|
Made changes as per the review. Thank you |
| if (numbers.length === 0) return null; | ||
|
|
||
| // Sort numbers without modifying original list | ||
| const sorted = [...numbers].sort((a, b) => a - b); |
There was a problem hiding this comment.
Is it necessary to make a copy of numbers before sorting?
There was a problem hiding this comment.
No, it is not necessary to make a copy of numbers before sorting, however, it is a good practice.
There was a problem hiding this comment.
Can you elaborate how it is a good practice in this scenario?
There was a problem hiding this comment.
In this scenario it is not needed. I just tried to make it cleaner by removing non numeric values if any. Do you want me to remove it?
There was a problem hiding this comment.
"... to make it cleaner by removing non numeric values" -- You have already removed non numeric values using .filter().
You can keep the code unchanged. I am more interested in knowing why you think "making a copy of numbers before sorting" is a good practice. Can you explain?
There was a problem hiding this comment.
Ok. I got your point. According to me, making a copy before sorting is a good practice for the following reasons:
- We could accidentally modify it for example if we use the median function directly, the new file would be sorted and it would replace the original file
- Incase we need to refer the original file later in the code, we will not be able to since the index of the original file could get sorted
I hope this answers. If i have missed anything, pl add to it. Thank you
There was a problem hiding this comment.
-
By "file", do you mean "array"?
-
It's true that
numbers.sort()can mutate thenumbersarray. If we need to usenumbersafter sorting, then it is considered a safe practice to not mutate the array. In your implementation, isnumbersbeing used after sorting?
There was a problem hiding this comment.
• Yes by file I meant array.
• No, in my current implementation code, the numbers array is not used again after the sorted variable is created.
There was a problem hiding this comment.
"immutability" do has its advantage. The reasons you gave do not quite fit the numbers array as the array is clearly not needed after sorting.
Thought you might be interested in this ChatGPT explaination:
https://chatgpt.com/share/69cf697a-5ea8-8331-bb33-47ccc8b02a17
There was a problem hiding this comment.
Ok. I will look at it in detail. Thank you
|
Have made the changes as per the feedback. Thank you |
|
Can you address this follow-up comment: #1005 (comment)
Other changes are good. |
|
Closing PR because the January ITP run has finished. Feel free to re-open if you're still working on it. |

Self checklist
Changelist
In this PR, i have implemented functions according to requrements and built test cases