Sheffield | ITP-Jan-26 | Hayriye Saricicek | Sprint 1| Module-Data-Groups#1082
Sheffield | ITP-Jan-26 | Hayriye Saricicek | Sprint 1| Module-Data-Groups#1082mshayriyesaricicek wants to merge 8 commits intoCodeYourFuture:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
cjyuan
left a comment
There was a problem hiding this comment.
The "Sprint-1" folder has a few more sub-folders containing files to be updated.
| describe("findMax.js", () => { | ||
| test.each([ |
There was a problem hiding this comment.
Should you need to classify test data into different categories, you can write:
describe("findMax -- description of category 1", () => {
test.each(
...
);
});
describe("findMax -- description of category 2", () => {
test.each(
...
);
});
...
| if (!foundValid) { | ||
| //if no valid numbers found, returns"-Inifinity" this includes invalid data and empty arrays | ||
| return -Infinity; | ||
| } |
There was a problem hiding this comment.
If foundValid remains false, then max would remain unchanged. So even without using foundValid and without this if statement and, the function would still return -Infinity.
There was a problem hiding this comment.
thank you for explaining
| const result = sum(input); | ||
|
|
||
| if (typeof expected === "number") { | ||
| expect(Math.abs(result - expected)).toBeLessThan(1e-10); // for special cases of decimals to avoid precision issues |
There was a problem hiding this comment.
You can also use expect(result).toBeCloseTo(expected).
There was a problem hiding this comment.
thank you, that is useful to know
There was a problem hiding this comment.
Note: They are not entirely equivalent though.
expect(result).toBeCloseTo(expected, 10) is closer to (Math.abs(result - expected)).toBeLessThan(0.5e-10)
The default value of the second parameter is 2 (surprisingly). So
expect(result).toBeCloseTo(expected) is closer to (Math.abs(result - expected)).toBeLessThan(0.005)
(Note: 0.5e-2 = 0.5 * 10**-2 = 0.5 * 0.01 = 0.005)
| total += val; //adds number to sum | ||
| } | ||
|
|
||
| return foundValid ? total : "Invalid Input"; // if at least one valid value is found return sum if no valid number is found return Invalid Input |
There was a problem hiding this comment.
What do you think about designing the function to support this behavior?
sum(["A"]) + sum([2]) == sum(["A", 2])
There was a problem hiding this comment.
I don't understand what it is you want me to do. The idea of the function is to add numbers together and ignore everything else so I am not sure why you are asking me to do this.
There was a problem hiding this comment.
sum(array1) + sum(array2) == sum(array1.concat(array2))
Both sides are two different ways to compute "sum of all the elements in array1 and array2".
Normal expectation is that the equality should hold.
However, if array1 is ["A"] and sum(array1) returns "Invalid Input" instead of 0, then the equality would break.
As a result, in my opinion, 0 is a more appropriate value to return when an array contains only non-numeric values.
|
Did you make any new commits? If you did, don't forget to push them to GitHub too. I will mark this PR as Complete first. |
Self checklist
Changelist
Exercises for Sprint 1