Skip to content

Conversation

@Abrsh100
Copy link

@Abrsh100 Abrsh100 commented Nov 3, 2025

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

I have done all the tasks required for this sprint

Questions

No questions

@Abrsh100 Abrsh100 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 3, 2025
Copy link
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

Code is good. I only have few suggestions.

Comment on lines 23 to 33
// Then it should return a copy of the original array
test("given an array with no duplicates", () => {
const input = [1, 2, 3, 4, 5];
const result = dedupe(input);
expect(result).toEqual([1, 2, 3, 4, 5]);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

The current test code cannot check if the returned array is a copy of the original array because toEqual() compares objects (including arrays) by value. To illustrate,

  const A = [2, 3, 1];
  const B = [...A];          // B is a copy of A
    
  // This set of code cannot distinguish if the compared objects are the same objects.
  expect(A).toEqual(A);  // true
  expect(A).toEqual(B);  // true

In order to check if the returned array is a copy of the original array, we would need additional checks.
Can you find out what code you need to add in order to ensure the returned value is not the original array?

function sum(elements) {
}
if (!Array.isArray(elements)) return null
const sumNum = elements.filter(n => typeof n === 'number' && !isNaN(n))
Copy link
Contributor

Choose a reason for hiding this comment

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

If you were required to filter out also Infinity and -Infinity, how would you express the filtering condition?

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 15, 2025
@Abrsh100 Abrsh100 added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Nov 19, 2025
Copy link
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

Can you also respond to this question ?

image

Comment on lines 1 to 13
function dedupe(groupNumber) {
return [...new Set(groupNumber)];
const seen = new Set()
const deduped = []

for (const item of groupNumber) {
if (!seen.has(item)) {
seen.add(item)
deduped.push(item)
}
}

return deduped
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why replaced the previous single-line statement with 10 lines code?

Comment on lines 2 to 8
if (!Array.isArray(elements)) return null
const sumNum = elements.filter(n => typeof n === 'number' && !isNaN(n))
return sumNum.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
};

return elements.reduce((accumulator, currentValue) => {
if (typeof currentValue === "number") {
return accumulator + currentValue;
}
return accumulator;
}, 0);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why rewrote the code?

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 19, 2025
@Abrsh100 Abrsh100 added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Nov 19, 2025
@cjyuan
Copy link
Contributor

cjyuan commented Nov 20, 2025

I wasn't asking you to change code.

Can you respond to my questions?

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 20, 2025
@Abrsh100
Copy link
Author

I am sorrry which question did I didn't respond

@Abrsh100 Abrsh100 added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Nov 20, 2025
@cjyuan
Copy link
Contributor

cjyuan commented Nov 20, 2025

All of these (see pic). You made some changes accordingly but that was not the same as responding to the comments. When I asked, "Why rewrote this code?", I literally wanted to know the rationale behind your decision.

image

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 20, 2025
@Abrsh100
Copy link
Author

yes I got it now sorry for not responding properly.
at dedube js. I change the code becouse i want the code in line 32 (dedube.test.js) is not a copy , which i was wrong so i serach and find out that to make sure that both of the input and result are copy of each ather i have to use toStrictEqual.

in sum.js I rewrote the code because I thought that if there is a value wich is nan the sum,test.js will throw an error but when i notice that the tests are writen to ignor the NAN and add the Number there fore i writern to my first code and this code ignor the NAN. by the .filter() in which only number are included in the summation

@Abrsh100 Abrsh100 added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Nov 26, 2025
Comment on lines 23 to 33
// Then it should return a copy of the original array
test("given an array with no duplicates", () => {
const input = [1, 2, 3, 4, 5];
const result = dedupe(input);
expect(result).toStrictEqual([1, 2, 3, 4, 5]);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

"A is a copy of B" means A and B refer to two different arrays.

The check you have does not check if result and input are two different arrays; it only checks if
result and [1,2,3,4,5] have the same type and elements.

Suggestion: look up "How to check if two arrays are different arrays with the same content in Jest?"

Comment on lines 3 to 5
if (typeof currentValue === "number" && Number.isFinite(currentValue)) {
return accumulator + currentValue;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI, the condition can further simplified.

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 26, 2025
@cjyuan cjyuan added the Reviewed Volunteer to add when completing a review with trainee action still to take. label Nov 26, 2025
@Abrsh100 Abrsh100 added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Dec 1, 2025
const input = [1, 2, 3, 4, 5];
const result = dedupe(input);
expect(result).toStrictEqual([1, 2, 3, 4, 5]);
expect(result).not.toBe([1, 2, 3, 4, 5]);
Copy link
Contributor

Choose a reason for hiding this comment

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

The syntax [1, 2, 3, 4, 5] always creates a new array.

On line 32, the statement is not checking if result and the array passed to dedupe() are different arrays.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants