generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 222
West Midlands | 25 Sep ITP | Iswat Bello | Sprint 1 | Module Data Groups #829
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
Closed
Closed
Changes from all commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
6e09b64
Add initial mean.js and mean.test.js files
Iswanna 49b82d5
Write a test for the function in the median.js file.
Iswanna 94d5edf
Implement calculateMedian function
Iswanna b6b2060
Add functions, extra code, and explanatory comments to mean-median.js…
Iswanna 935e47e
Add a return statement to the function calculateMean
Iswanna dfe0f44
Export function to test file using module.exports
Iswanna 22abc47
Import calculateMean function from mean.js
Iswanna e0bed31
Import calculateMedian function from median.js
Iswanna e092070
Add package.json file
Iswanna 4fe7d13
Comment out function that mutates array with splice
Iswanna f729643
Add function to calculate median without mutating the array
Iswanna 3449f32
Add Jest test case to verify that the function implementation does no…
Iswanna 696f20b
Add a Jest test case to check that calculateMedian returns the correc…
Iswanna 2bf9d3c
Update function implementation to handle even-length arrays when calc…
Iswanna f658cab
Remove function call and console.log debugging statements
Iswanna 7ecf949
Fix inconsistent indentation in jest test
Iswanna c217567
Add input validation to return null when a non-array is passed
Iswanna d75a3ce
Reformat median test suite for readability
Iswanna 4040d9b
Add validation to ensure input is an array
Iswanna 57c20f4
Filter out non-numeric values from the array and assign its reference…
Iswanna 8a41346
Add statements to duplicate the input array and sort it in ascending …
Iswanna 17d40f7
Add logic to calculate the median for arrays with odd or even lengths
Iswanna a22309d
Add test case to ensure `dedupe` returns an empty array for empty input
Iswanna 8d14298
Make function accessible in other files by adding module.exports
Iswanna 50670f0
Add test case for `dedupe` to ensure it returns a copy of the array w…
Iswanna 63e538f
Refactor test cases to data-driven format using an array and loop
Iswanna 950a4a3
Add test case to ensure dedupe removes duplicates and keeps the first…
Iswanna 37d1133
Comment out unused test.todo
Iswanna 1f17291
Add additional test cases for no duplicates, duplicate and mixed str…
Iswanna a73b980
Add case to verify dedupe removes invalid elements and duplicates, re…
Iswanna 4ea5009
Remove the semi-colon after the expect expression
Iswanna e8bda7b
Add test case in invalid elements category to ensure NaN is ignored
Iswanna c5249d9
Rename describe block to 'dedupe - valid inputs'
Iswanna e95f6a4
Add describe block for invalid inputs and a test case to ensure dedup…
Iswanna 4e105a6
Remove the if statement that checks if length of the array is equlas …
Iswanna ae9fb0e
Add input validation for non-array values
Iswanna 54e1a28
Add implementation for when empty array is passed as input
Iswanna 52e97c6
Update dedupe test cases for correct expected output
Iswanna ba0eff3
Implement dedupe function to remove duplicate numbers and strings,
Iswanna 0da3ea8
Refactor condition in dedupe for easier reading and parsing
Iswanna a7e57bf
Remove console.log statement used for debugging
Iswanna 06f06ed
Add comments to clarify dedupe implementation
Iswanna b38a131
Replace test.todo with actual test cases for findMax
Iswanna 110ef31
Add tests for non-array inputs in findMax
Iswanna 6e91a42
Change deduplicate back to dedupe
Iswanna bd49eed
Add findMax implementation for numeric arrays and handle empty array …
Iswanna 7957277
Add logic to findMax to handle non-array inputs by throwing a TypeError
Iswanna b3a96a6
Add full findMax implementation:
Iswanna 68b5557
Add multiple test cases for each findMax scenario
Iswanna d5d84f7
Add comments to each acceptance criteria scenario
Iswanna 4882181
Remove .todo and add test cases for each scenario of the sum function
Iswanna 1cad41b
Implement sum function to pass all acceptance criteria test cases
Iswanna ba35631
Update input and expected value for test when array contains non-numb…
Iswanna 9f244db
Add additional test cases for each acceptance criteria scenario
Iswanna 973758b
Refactor the implementation of includes to use a for...of loop
Iswanna 0fb3f24
Remove redundant variable element and use item in the if statement
Iswanna e5e09ee
Refactor calculateMedian to remove unnecessary intermediate array clone
Iswanna 9ed4c2c
test: ensure dedupe returns a new array copy
Iswanna f6c5f8a
Update sum.test.js to use toBeCloseTo for decimal/float sums
Iswanna 68a0f81
Refactor calculateMedian by removing unnecessary array copy
Iswanna 3b01cee
Fix errors and omissions in findMax tests: add missing assertions and…
Iswanna 0a5cd81
Remove .toFixed(2) when returning the numeric value of sumElements
Iswanna d112b5b
Remove explicit precision from `toBeCloseTo` test cases
Iswanna b32105e
Remove redundant Number() conversion around sumElement
Iswanna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,43 @@ | ||
| function dedupe() {} | ||
| // This defines a function named dedupe with a parameter arrayInput. arrayInput should be an array. | ||
| function dedupe(arrayInput) { | ||
| // This checks whether the input is not an array. | ||
| if (!Array.isArray(arrayInput)) { | ||
| // If the input is not an array, the function stops, throws a TypeError and shows an error message saying:“Input must be an array.” | ||
| throw new TypeError("Input must be an array"); | ||
| } | ||
| // This checks if the array is empty (has no elements). | ||
| if (arrayInput.length === 0) { | ||
| // If the array is empty, it returns an empty array. | ||
| return []; | ||
| } | ||
|
|
||
| // This declares a new variable `newArray` which will hold a reference to an empty array in memory | ||
| const newArray = []; | ||
| // This decares a new varibale `seen` which will hold a reference to the actual set object in memory | ||
| const seen = new Set(); // variable seen keeps track of all items that have already been added to the result array | ||
| // seen is a Set object that remembers items, | ||
|
|
||
| // newArray is an array that holds the actual result. | ||
|
|
||
| // This starts a loop that goes through each element in the input array one by one. | ||
| for (const item of arrayInput) { | ||
| // This big condition checks two things before adding an item: | ||
|
|
||
| // !seen.has(item) — The item has not been added before. | ||
|
|
||
| // The item is either a number (but not NaN) or a string. | ||
| // So only real numbers and strings that haven’t appeared yet will be kept. | ||
| if ( | ||
| !seen.has(item) && | ||
| ((typeof item === "number" && !Number.isNaN(item)) || | ||
| typeof item === "string") | ||
| ) { | ||
| newArray.push(item); // If the item passes the condition, it gets added to the new array. | ||
| seen.add(item); // The item is then recorded in the Set, so it won’t be added again later. | ||
| } | ||
| } | ||
| // After the loop finishes, return the final deduplicated array | ||
| return newArray; // After checking all items, the function returns the new array with duplicates removed and invalid items filtered out. | ||
| } | ||
|
|
||
| module.exports = dedupe; // This line allows the dedupe function to be used in other files (like the test file). |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,12 @@ | ||
| function findMax(elements) { | ||
| if (!Array.isArray(elements)) { | ||
| throw new TypeError("Input must be an array"); | ||
| } else { | ||
| const filteredArray = elements.filter( | ||
| (ele) => typeof ele === "number" && !isNaN(ele) | ||
| ) | ||
| return Math.max(...filteredArray); | ||
| } | ||
| } | ||
|
|
||
| module.exports = findMax; |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,16 @@ | ||
| function sum(elements) { | ||
| if (!Array.isArray(elements)) { | ||
| throw new TypeError("Input must be an array"); | ||
| } | ||
| const filteredElements = elements.filter( | ||
| (ele) => typeof ele === "number" && !isNaN(ele) | ||
| ); | ||
| let sumElements = 0; | ||
|
|
||
| for (const item of filteredElements) { | ||
| sumElements += item; | ||
| } | ||
| return sumElements; | ||
| } | ||
|
|
||
| module.exports = sum; |
Oops, something went wrong.
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.
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.
Nicely done.
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.
Thank you.