Repository navigation
London | 26-ITP-Sep | Shirin Panahian | Sprint 1 | Complete sprint 1 exercises - #1498
shirinpanahian wants to merge 15 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
cjyuan
left a comment
There was a problem hiding this comment.
-
Function implementations are all correct. Well done.
-
Regarding the PR description, could you use AI to research what should be included in the "Changelist" section of a PR, then revise your Changelist content accordingly?
| const copy = [...list]; | ||
| const middleIndex = Math.floor(listLength / 2); | ||
| copy.sort((a, b) => a - b); |
There was a problem hiding this comment.
Could also use Array.prototype.toSorted().
cjyuan
left a comment
There was a problem hiding this comment.
Changes look good.
I think one of the functions may not pass the tests you prepared.
| if (newList.includes(item)) { | ||
| continue; | ||
| } | ||
| newList.push(item); |
There was a problem hiding this comment.
Note: Could also write
if (!newList.includes(item)) {
newlist.push(item);
}There was a problem hiding this comment.
thank you , that was good idea👍
| describe("findMax", () => { | ||
| it("given an empty array,returns -Infinity", () => { | ||
| expect(findMax([])).toEqual(-Infinity); | ||
| }); |
There was a problem hiding this comment.
Did you ran the test script after you made the changes?
There was a problem hiding this comment.
The issue is fixed, and the tests are now passing.
cjyuan
left a comment
There was a problem hiding this comment.
Changes look good. Well done.
| if (arrLength === 0) { | ||
| return -Infinity; | ||
| } | ||
|
|
||
| for (const item of elements) { | ||
| if (maxNum < item) { | ||
| maxNum = item; | ||
| } | ||
| } |
There was a problem hiding this comment.
Note: The code on lines 12, 17-21 also works for empty array.
Learners, PR Template
Self checklist
Task code
CYF-1071
Changelist
Changelist
Implemented
dedupe: Removes duplicate elements from an array while preserving the original order and first occurrence of each element. Handles empty arrays and arrays without duplicates.Implemented
findMax: Finds and returns the largest number in an array, with handling for empty arrays, single-element arrays and invalid inputs.Implemented
sumandmean: Added the functions to calculate the sum and arithmetic mean of an array of numbers.Implemented
calculateMedian: Calculates the median of an array of numbers, supporting both odd and even numbers of elements. Includes input validation and error handling.Implemented
describeMedian: Returns a descriptive message containing the calculated median, or an appropriate error message when the median cannot be calculated.Refactored
includes: Updated the implementation to use afor...ofloop.Added and updated tests: Expanded test coverage for normal cases, empty arrays, single-element arrays, duplicate elements and invalid inputs.