-
-
Notifications
You must be signed in to change notification settings - Fork 147
London | May-2025 | Ikenna Agulobi | Data Groups | sprint-1 #575
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 19 commits
2f37fe6
e110223
ab874b4
997ad4f
51955ab
aed7949
62a5f73
d8ab058
28b37ee
c8db981
bf98503
5ad878d
df4c578
e057adb
bda9ea1
ee338d1
d6d520d
c7d1caf
b226613
7c847c5
9c35969
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,7 @@ | ||
function dedupe() {} | ||
function dedupe(arr) { | ||
const newArray = [... new Set(arr)] | ||
return newArray; | ||
}; | ||
Comment on lines
+1
to
+4
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. have you tested this? does it run or is there a syntax error? Do you understand how the Set works? 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. I tested my code and it does work. |
||
|
||
// console.log(dedupe(["b", "c", "a", "b", "c", 1, "a", 2])); | ||
module.exports = dedupe; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,21 @@ | ||
function findMax(elements) { | ||
let numbers = []; | ||
// using for loop to extract numbers from the Array incase array is mixed | ||
for (let i = 0; i < elements.length; i++) { | ||
if (typeof elements[i] === "number") { | ||
numbers.push(elements[i]); | ||
} | ||
} | ||
// Return the largest number, else -Infinity if no numbers are found | ||
if (numbers.length > 0) { | ||
return Math.max(...numbers); | ||
} else { | ||
return -Infinity; | ||
} | ||
} | ||
|
||
// console.log(findMax([1, 2, 3, 4, 10])); | ||
// console.log(findMax([])); | ||
// console.log(findMax([1])); | ||
// console.log(findMax( [4, "hello", "fruit", 2, 5])) | ||
module.exports = findMax; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,21 @@ | ||
function sum(elements) { | ||
let onlyNumbers = []; | ||
//Extract numbers from the Array incase array is mixed | ||
for (let i = 0; i < elements.length; i++) { | ||
if (typeof elements[i] === "number") { | ||
onlyNumbers.push(elements[i]); | ||
} | ||
} | ||
if (onlyNumbers.length > 0) { | ||
return onlyNumbers.reduce((a, b) => a + b); | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
console.log(sum([10, 20, 30])); | ||
console.log(sum(["hey", 10, "hi", 60, 10])); | ||
console.log(sum([])); | ||
|
||
|
||
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.
This is correct! Do you understand why we also need
!isNaN
here?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! We need !isNaN in my function so that it filters real usable numbers and ignore anything that is not a real number like 'NaN".