Skip to content

WEST MIDLANDS-JAN-ITP|SEGUN FOLAYAN|DATA GROUPS|SPRINT-1 #473

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

segunfolayan
Copy link

Learners, PR Template

Self checklist

  • [x ] I have committed my files one by one, on purpose, and for a reason
  • [ x] I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
  • [ x] I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

Questions

Ask any questions you have for your reviewer.

@segunfolayan segunfolayan added the Needs Review Participant to add when requesting review label Mar 31, 2025
@day-lee day-lee self-requested a review April 7, 2025 10:11
@day-lee day-lee added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Participant to add when requesting review labels Apr 7, 2025
@@ -4,8 +4,17 @@

function calculateMedian(list) {
const middleIndex = Math.floor(list.length / 2);
const median = list.splice(middleIndex, 1)[0];
return median;
const median=0;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your logic is good, but the code looks a bit repetitive. The variable median is unnecessary. Could you refactor the code to return the result directly instead of assigning it to the variable median?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function calculateMedian(list) {
const middleIndex = Math.floor(list.length / 2);

if (list.length % 2 === 1) {
return list[middleIndex];
}

return (list[middleIndex] + list[middleIndex - 1]) / 2; lists
}

module.exports = calculateMedian;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you



function dedupe(arr) {
return [...new Set(arr)];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain the characteristics of Set object and why we need to use the spread operator here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Uniqueness-It does not contain duplicates.
  2. No index access- IT cannot be accessed using indices like arrays.
  3. Insertion order-The values in the set are iterated in the order in which they are added.
  4. Type flexibility- A Set can store values of any type (primitive or object), and even objects can be stored as unique values (by reference).
  5. The spread operator is used to convert the Set back into an array.
  6. Thank you

}

}
return total;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaScript uses floating-point numbers, which are not always precise and lead to rounding issues.
If you test the following line expect(sum([1.6, 2.5, 3.1])).toBe(7.2) It will cause an error.
Can you refactor the sum() function so it passes this test case?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function sum(elements) {
let total = 0;
for (let Index = 0; Index < elements.length; Index++) {
if (typeof elements[Index] === "number") {
total += elements[Index];
} else {
total = total + 0;
}
}
return parseFloat(total.toFixed(10));
}

.......................Thank you


// Given an array with decimal/float numbers
// When passed to the sum function
// Then it should return the correct total sum
test("given an array with decimal/float numbers, then it should return the correct sum", () => {
expect(sum([1.25,1.75,1.6])).toEqual(4.6);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add expect(sum([1.6, 2.5, 3.1])).toBe(7.2) and refactor the code to pass the test?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function sum(elements) {
let total = 0;
for (let Index = 0; Index < elements.length; Index++) {
if (typeof elements[Index] === "number") {
total += elements[Index];
} else {
total = total + 0;
}
}
return parseFloat(total.toFixed(10));
}

module.exports = sum;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many Thanks

@day-lee day-lee added Reviewed Volunteer to add when completing a review and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Apr 7, 2025
@day-lee
Copy link

day-lee commented Apr 7, 2025

Good job 👍 Let me know if you have any questions!

@segunfolayan segunfolayan added the Complete Participant to add when work is complete and review comments have been addressed label Apr 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Complete Participant to add when work is complete and review comments have been addressed Reviewed Volunteer to add when completing a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants