-
-
Notifications
You must be signed in to change notification settings - Fork 178
Birmingham | 25-ITP-Sep | Joy Opachavalit | Sprint 1 | Sprint-1 #800
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,15 @@ | ||
| function dedupe() {} | ||
|
|
||
| function dedupe(arr) { | ||
| if (!Array.isArray(arr)) return []; | ||
| const seen = new Set(); | ||
| const result = []; | ||
| for (const item of arr) { | ||
| if (!seen.has(item)) { | ||
| seen.add(item); | ||
| result.push(item); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| module.exports = dedupe; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,26 @@ | ||
| function findMax(elements) { | ||
| } | ||
| // Filter only numeric values (numbers, not NaN, not null, not undefined) | ||
| const numbers = elements.filter(function(item) { | ||
| return typeof item === 'number' && !isNaN(item); | ||
| }); | ||
|
|
||
| // Check if any numbers exist, Given an empty array, it should return -Infinity | ||
| if (numbers.length === 0) { | ||
| if (elements.length === 0) { | ||
| return -Infinity; | ||
| } else { | ||
| return null; | ||
| } | ||
| } | ||
|
Comment on lines
+8
to
+14
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could also consider an array with no numbers the same as an array with no elements. The latter also does not have any number. |
||
|
|
||
| // Find the maximum number | ||
| let max = numbers[0]; | ||
| for (let i = 1; i < numbers.length; i++) { | ||
| if (numbers[i] > max) { | ||
| max = numbers[i]; | ||
| } | ||
| } | ||
| return max; | ||
| } | ||
|
Comment on lines
+18
to
+24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you improve the indentation of this code? |
||
|
|
||
| module.exports = findMax; | ||
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.
The current test code cannot check if the returned array is a copy of the original array because
toEqual()compares objects (including arrays) by value. To illustrate,In order to check if the returned array is a copy of the original array, we would need additional checks.
Can you find out what code you need to add in order to ensure the returned value is not the original array?