-
-
Notifications
You must be signed in to change notification settings - Fork 208
Glasgow | 25-ITP-SEP | Hanna Mykytiuk | Sprint 1 | Coursework #817
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
Conversation
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
5 similar comments
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Sprint part (Module-Data-Groups) doesn't match expected format (example: 'Sprint 2', without quotes) If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
cjyuan
left a comment
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.
The PR title and the PR description are not quite in the expected format.
Can you update them according to this PR Guide?
| if (numbersOnly.length == 0){ | ||
| return null; | ||
| } | ||
| const sorted =[...numbersOnly].sort((a,b) => a-b ); //we created a new arrey where we saved sorted element (as string) and turned them to numbers. |
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.
numbersOnly is no longer the original array and it is not needed later.
So we could improve the performance by not making another copy of the array and
write the code on line 16 as
const sorted = numbersOnly.sort((a, b) => a - b); // sorted and numbersOnly are the same arrayNote: sorted is a more meaningful name so it is good to keep it.
| // Then it should return a copy of the original array | ||
|
|
||
| test("given an array with no duplicates, it should return a copy of the original array", () => { | ||
| const currentOutput = dedupe([5, 1, 2, 3, 8]); | ||
| const targetOutput = [5, 1, 2, 3, 8]; | ||
| expect(currentOutput).toEqual(targetOutput); | ||
| }); |
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 test should fail if the function returns the original array (instead of a copy of the original array).
The current test checks only if both the original array and the returned array contain identical elements.
In order to validate the returned array is a different array, we need an additional check.
Can you find out what this additional check is?
| test("given an array with non-number values, it should return the max and ignore non-numeric values", () => { | ||
| const currentOutput = findMax(["a", "!", 3, 5, "0"]); | ||
| const targetOutput = 5; | ||
| expect(currentOutput).toEqual(targetOutput); | ||
| }); |
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.
Does the following function call returned the value you expect?
findMax(["1000", 1]);
findMax([1000, "1"]);| test("given an array with only non-number values, it should return the least surprising value given how it behaves for all other inputs", () => { | ||
| const currentOutput = findMax(["2", "3", "$", "%"]); | ||
| const targetOutput = "3"; | ||
| expect(currentOutput).toEqual(targetOutput); | ||
| }); |
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.
Why is "3" considered the least surprising value? What's your rationale?
| test("given an array with decimal/float numbers, it should return the correct total sum", () => { | ||
| const currentOutput = sum ([2.5, 3.1, 4.9]); | ||
| const targetOutput = 10.5; | ||
| expect(currentOutput).toEqual(targetOutput); | ||
| }); |
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.
Decimal numbers in most programming languages (including JS) are internally represented in "floating point number" format. Floating point arithmetic is not exact. For example, the result of 46.5678 - 46 === 0.5678 is false because 46.5678 - 46 only yield a value that is very close to 0.5678. Even changing the order in which the program add/subtract numbers can yield different values.
So the following could happen
expect( 1.2 + 0.6 + 0.005 ).toEqual( 1.805 ); // This fail
expect( 1.2 + 0.6 + 0.005 ).toEqual( 1.8049999999999997 ); // This pass
expect( 0.005 + 0.6 + 1.2 ).toEqual( 1.8049999999999997 ); // This fail
console.log(1.2 + 0.6 + 0.005 == 1.805); // false
console.log(1.2 + 0.6 + 0.005 == 0.005 + 0.6 + 1.2); // falseCan you find a more appropriate way to test a value (that involves decimal number calculations) for equality?
Suggestion: Look up
- Checking equality in floating point arithmetic in JavaScript
- Checking equality in floating point arithmetic with Jest
| if (elements.length == 0){ // check if array is empty | ||
| return 0; | ||
| } | ||
| if (elements.length === 1){ //check if array has one element | ||
| return elements[0]; | ||
| } | ||
| let sum = 0; | ||
| let isNumbersPresent = elements.some(item => typeof item === 'number' && !isNaN(item)); | ||
| for (let i =0; i<elements.length; i++){ //sum of elements | ||
| if (typeof elements[i] === 'number'){ //check if element is number | ||
| sum += elements[i]; | ||
| } | ||
| if (isNumbersPresent == false && !isNaN(elements[i])){ //1) check if array doesnt have numbers; 2)check if element can be conversted to number | ||
| sum += parseFloat(elements[i]); // add converted to num element | ||
| } | ||
| } | ||
| return 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.
Does the following function calls return the value you expected?
sum([NaN, 1]);
sum(["A"]);
sum(["10", 1]);
sum(["10", "1"]);
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Sprint part (Module-Data-Groups) doesn't match expected format (example: 'Sprint 2', without quotes) If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above. |
1 similar comment
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Sprint part (Module-Data-Groups) doesn't match expected format (example: 'Sprint 2', without quotes) If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above. |
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above. |
Learners, PR Template
Self checklist
Changelist
Sprint 1 exercises completed.
Questions
No questions