-
-
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
54e1b79
fbf6020
529da6a
c60f88b
0c29f69
0010e7a
1fc8747
f6083e7
b491654
d687740
216f7f3
5d5b337
59d09f8
93daaa0
7cfd741
1c702e3
9d5a0fe
2c93367
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,10 @@ | ||
| 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,14 @@ | ||
| 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,17 @@ | ||
| 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; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,11 @@ | ||
| function contains() {} | ||
| function contains(obj, property) { | ||
| // Check that 'obj' is a valid, non-array object | ||
| if (typeof obj !== "object" || obj === null || Array.isArray(obj)) { | ||
| return false; | ||
| } | ||
|
|
||
| // Object.hasOwn checks if the key directly exists on the object | ||
| return Object.hasOwn(obj, property); | ||
| } | ||
|
|
||
| module.exports = contains; |
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