-
-
Notifications
You must be signed in to change notification settings - Fork 156
London | 25-ITP-May | Houssam Lahlah | Sprint 1 | Sprint-1 #785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Properly calculates median for odd and even-length arrays - Handles unsorted arrays - Filters out non-numeric values - Returns null for invalid or empty inputs - Ensures the input array is not modified
- Added dedupe.js to remove duplicate elements from arrays while preserving first occurrence - Handles empty arrays, arrays with numbers, strings, or mixed values - Added dedupe.test.js covering: • empty array • arrays with no duplicates • arrays with duplicate strings, numbers, and mixed values - Ensures original array is not modified
- Added max.js to find the largest numerical element in an array - Ignores non-numeric values - Handles empty arrays, negative numbers, decimal numbers, and mixed-type arrays - Added max.test.js covering: • empty array • single-element array • positive and negative numbers • decimal numbers • arrays with non-number values • arrays with only non-number values
- Added sum.js to calculate the total sum of numerical elements in an array - Ignores non-numeric values - Handles empty arrays, negative numbers, decimal numbers, and mixed-type arrays - Added sum.test.js covering: • empty array • single-element array • positive and negative numbers • decimal numbers • arrays with non-number values • arrays with only non-number values
- Refactored includes.js to iterate over array elements using a for...of loop - Preserves original behavior: • returns true if target is found • returns false if target is not found - All existing tests in includes.test.js remain passing
- Implemented calculation of final frequency. - Implemented detection of first repeated frequency. - Reads input from input.txt and logs results to console.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good start on this sprint's tasks, I have spotted a few areas where you could improve code further
Did you mean to make changes to the package.json files? We try to keep pull requests specific to just the files in the feature we are changing.
q1: For edge cases, the idea is that you've covered what is correct and most of the common "wrong" values or types that might be given. For most ttasks would be difficult to find every possible edge case to test. It looks to me like you have done a good job of finding possible test cases in these tasks.
q2: The for..of you have used is correct.
const median = list.splice(middleIndex, 1)[0]; | ||
return median; | ||
// Sort numbers in ascending order | ||
numbers.sort((a, b) => a - b); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to include this anonymous sorting function as an argument to sort?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello LonMcGregor,
Thank you for the feedback!
I double-checked the sort function—using (a, b) => a - b is necessary to sort numbers numerically; otherwise, JavaScript sorts them as strings, which would break the median calculation.
I also removed the splice approach from my earlier attempt to avoid mutating the array—returning numbers**[middleIndex]** directly works cleanly for odd-length arrays.
…ing the array; retain numeric sort for correct median calculation
Self checklist
Changelist
1. Sum of Numbers (sum.js)
2. Maximum Number (max.js)
3. Deduplicate Array (dedupe.js)
4. Median Calculation (calculateMedian.js)
5. Includes (includes.js)
6. Advent of Code 2018 Day 1 (Chronal Calibration)
Questions