Manchester | 26-ITP-Jan | Abdu Hassen | Sprint 1| Data-Grouping#1120
Manchester | 26-ITP-Jan | Abdu Hassen | Sprint 1| Data-Grouping#1120Abduhasen wants to merge 5 commits intoCodeYourFuture:mainfrom
Conversation
Sprint-1/fix/median.js
Outdated
| return null; | ||
| } | ||
|
|
||
| list = list.filter((value) => typeof value === "number"); |
There was a problem hiding this comment.
Do you plan to consider also -Infinity, Infinity, and NaN in the median calculation (and in the functions in implement/max.js and implement/sum.js)?
There was a problem hiding this comment.
to handle all type of input i changed the filter , using built in method of Number.isFinite(value) can handle all type of values.
There was a problem hiding this comment.
Why not apply the change also to findMax() and sum()?
Sprint-1/fix/median.js
Outdated
| return (list[middleIndex - 1] + list[middleIndex]) / 2; | ||
| } else { | ||
| const middleIndex = Math.floor(list.length / 2); | ||
| const median = list.splice(middleIndex, 1)[0]; |
There was a problem hiding this comment.
Why not use the same syntax you were using on line 24 to access an array element?
There was a problem hiding this comment.
i was writing the codes each one by one that why i forgot to combine them and some times little bit confusing putting line of codes together if you have any recommendation of books or techniques that i can read that would be helpful. thank you.
There was a problem hiding this comment.
After the implemented function is working correctly, we should refactor our code to further improve the code. The process involves reviewing the code carefully, and reading code is a skill that takes time to develop (through reading and writing more code).
If you want something to read, you can try https://javascript.info/
| test("The function should return a copy of the original array if the array contains no duplicates", () => { | ||
| const original = [2, 4, 5, 6, 8]; | ||
| expect(dedupe(original)).toEqual(original); | ||
| expect(dedupe(original)).not.toBe(original); | ||
| }); |
There was a problem hiding this comment.
There is a chance that, even though the return value has incorrect elements (for example, [2, 2, 2, 2, 2]),
the two tests could still pass. Can you figure out why, and then fix the tests accordingly?
There was a problem hiding this comment.
i did some fixation now it is improved.
There was a problem hiding this comment.
It is not about how many sets of data you are testing, the issue in "how" you carry out the test.
Don't think how you implement your function. Think about under what condition a buggy function that returns [2, 2, 2, 2, 2] can possibly pass the test.
| expect(sum([7.8045, 1.273, 3.19])).toBeCloseTo(12.2675, 4); | ||
| expect(sum([4.6, 1.8, 3.18, 5.4])).toBeCloseTo(14.98); | ||
| expect(sum([11 / 12, 4 / 6, 1 / 2, 6 / 20])).toBeCloseTo(2.383333, 6); | ||
| expect(sum([1 / 2, 2 / 3, 3 / 4, 4 / 5, 5 / 6, 6 / 7])).toBeCloseTo( | ||
| 4.407142857, | ||
| 9 | ||
| ); |
There was a problem hiding this comment.
Why specify different "number of decimal places" in your tests?
There was a problem hiding this comment.
Because the more decimal places I expected value has, the stricter my test needs to be.
There was a problem hiding this comment.
Why not just enforce the strictest tolerable difference?
If the function can pass this test
expect(sum([7.8045, 1.273, 3.19])).toBeCloseTo(12.2675, 9);
then the function will also pass
expect(sum([7.8045, 1.273, 3.19])).toBeCloseTo(12.2675, 4);
For adding only a few numbers, the rounding error will be very small. So it's ok to be strict.
There was a problem hiding this comment.
ok i will implement that in fact in this test i did that the test go through all the decimal numbers until the end that's why i specified each decimal number to test.
cjyuan
left a comment
There was a problem hiding this comment.
You have all the info to further improve the code. I will mark this PR as complete first.
| expect(original1.length).toBe(new Set(original1).size); | ||
| const result1 = dedupe(original1); | ||
| expect(result1).toEqual(original1); | ||
| expect(result1).not.toBe(original1); |
There was a problem hiding this comment.
-
If their length is different,
toEqual()would also fail. -
Objects (including arrays) are passed to a function by reference, meaning that the they have a chance to be mutated by the function. So on line 30, it is safer to write
expect(reuslt1).toEqual('[2,4,5,6,8]').
Learners, PR Template
Self checklist
Changelist
-fixing and implementing of data on Javascript using loop,if statement.
-testing code using jest.
Questions
N/A