-
-
Notifications
You must be signed in to change notification settings - Fork 96
ITP JAN 25 | KatarzynaKazimierczuk | Data Groups | Sprint1 #474
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,11 @@ | ||
function dedupe() {} | ||
function dedupe(arr) { | ||
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 job using includes() and push() with new array. There is another solution using |
||
const modified = []; | ||
|
||
arr.forEach(el => { | ||
if (!modified.includes(el)) { | ||
modified.push(el) ; | ||
} | ||
}) | ||
return modified; | ||
} | ||
module.exports = dedupe; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,19 @@ | ||
function findMax(elements) { | ||
} | ||
// inf includes non-numerical and numberical | ||
//ignore non numerical | ||
let filtered = elements.filter(element => typeof element === 'number') | ||
|
||
//check if empty | ||
if (filtered.length === 0) { | ||
return -Infinity; | ||
} else if (filtered.length === 1) { | ||
return filtered[0] | ||
} else { | ||
//find max | ||
return Math.max(...filtered) | ||
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 explain why we need to use spread operator with Math.max() here? |
||
} | ||
|
||
} | ||
|
||
|
||
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.
You could return the result of
(list[middleIndex-1] + list[middleIndex]) /2
right away instead of assign the value to a median variable as median won't be used again.