-
-
Notifications
You must be signed in to change notification settings - Fork 312
Birmingham | 26-ITP-May | Ogbemi Mene | Sprint 1 | Module data group/sprint 1 #1254
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,9 @@ | ||
| function dedupe() {} | ||
| function dedupe(list) { | ||
| if (!Array.isArray(list)) { | ||
| return []; | ||
| } | ||
|
|
||
| return [...new Set(list)]; | ||
|
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. Good use of a set! |
||
| } | ||
|
|
||
| module.exports = dedupe; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,12 @@ | ||
| function findMax(elements) { | ||
| if (!Array.isArray(elements) || elements.length === 0) { | ||
| return -Infinity; | ||
| } | ||
| const numbersOnly = elements.filter(item => typeof item === 'number' && !isNaN(item)); | ||
| if (numbersOnly.length === 0) { | ||
| return -Infinity; | ||
| } | ||
| return Math.max(...numbersOnly); | ||
|
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 you maybe try re-implementing this without using the built-in max function? |
||
| } | ||
|
|
||
| module.exports = findMax; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,16 @@ | ||
| function sum(elements) { | ||
| if (!Array.isArray(elements) || elements.length === 0) { | ||
| return 0; | ||
| } | ||
|
|
||
| const numbersOnly = elements.filter(item => typeof item === "number" && !isNaN(item)); | ||
|
|
||
| if (numbersOnly.length === 0) { | ||
|
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. If you have 0 elements, do you need this if condition here? |
||
| return 0; | ||
| } | ||
|
|
||
| return numbersOnly.reduce((acc, curr) => acc + curr, 0); | ||
|
|
||
| } | ||
|
|
||
| module.exports = sum; | ||
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.
If you have test files, put the tests into those ones rather than leaving them in the main file