-
-
Notifications
You must be signed in to change notification settings - Fork 326
London | 26-ITP-May | Damilola Odumosu | Sprint 1 | Coursework #1296
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
3ac6be3
5fdea58
7bde1b5
64b9210
f1f59ac
b881892
f7ac75c
99aab16
5253409
cba6d18
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,9 @@ | ||
| function dedupe() {} | ||
| function dedupe(elements) { | ||
| if (elements.length === 0) { | ||
| return []; | ||
| } | ||
|
|
||
| return [...new Set(elements)]; | ||
| } | ||
|
|
||
| module.exports = dedupe; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,22 @@ | ||
| function findMax(elements) { | ||
| if (elements.length === 0) { | ||
| return -Infinity; | ||
| } | ||
| const elementLists = elements.filter((number) => { | ||
| return typeof number === "number"; | ||
| }); | ||
| if (elementLists.length === 0) { | ||
| return 0; | ||
| } | ||
|
Comment on lines
+8
to
+10
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. When a function is expected to return a number, it is better to design the function to always returned a value of type number for consistency. Technically, an empty array also an array containing no numbers.
Author
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. fixed to return 0
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. What's your decision process to select
Author
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. since the function is supposed to return a number i thought it best that if the array is empty /contain to numbers it should return 0
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. An empty array is also an array containing no numbers. So the function could also return the same value in both cases. However, if the function needs to distinguish an empty array from an array containing no numbers, then your choice would make sense. |
||
| if (elementLists.length === 1) { | ||
| return elementLists[0]; | ||
| } | ||
| let max = elementLists[0]; | ||
| for (let i = 1; i < elementLists.length; i++) { | ||
| if (elementLists[i] > max) { | ||
| max = elementLists[i]; | ||
| } | ||
| } | ||
| return max; | ||
| } | ||
|
|
||
| module.exports = findMax; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,10 @@ | ||
| function sum(elements) { | ||
| } | ||
| const elementsList = elements.filter((element) => Number.isFinite(element)); | ||
|
|
||
| let sum = 0; | ||
| for (let i = 0; i < elementsList.length; i++) { | ||
| sum += elementsList[i]; | ||
| } | ||
| return sum; | ||
|
Comment on lines
+4
to
+8
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 this code work for an array of any length?
Author
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. yes, so i think i dont have to check and return 0 if its empty because the loop will do that anyway, thank you, fixed
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. You also don't have to check if the array length is 1.
Author
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. yes, removed this |
||
| } | ||
| module.exports = sum; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
What is
result?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.
result saves the function call of dedeupe
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.
Is
resultdeclared and assigned any value?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.
yes i see the problem now, i have fixed it