-
Notifications
You must be signed in to change notification settings - Fork 188
#1-4Task. Khamets_Alexander #924
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
base: master
Are you sure you want to change the base?
Conversation
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.
I'll mark the PR as "Draft", please click "ready for review" when it will be finished. Thank you!
task/01-strings-tasks.js
Outdated
let result = ''; | ||
|
||
for (let i = 0; i < count; i++) { | ||
result += value; | ||
} | ||
return result; |
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.
Please, solve this task using
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat
task/02-numbers-tasks.js
Outdated
*/ | ||
function getDistanceBetweenPoints(x1, y1, x2, y2) { | ||
throw new Error('Not implemented'); | ||
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)); |
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.
Please, solve it using
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot
task/02-numbers-tasks.js
Outdated
*/ | ||
function getLinearEquationRoot(a, b) { | ||
throw new Error('Not implemented'); | ||
return (b === 0) ? 0 : -b / a; |
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.
Actually, we don't need to check b === 0, because -b / a equals zero if (b ===0)
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.
Actually, we don't need to check b === 0, because -b / a equals zero if (b ===0)
Hello. If i remove this check (b === 0), the result of the function will be -0 (minus zero). In this case the test with parameters a=5 and b = 0 fails.
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.
Actually, we don't need to check b === 0, because -b / a equals zero if (b ===0)
Hello. If i remove this check (b === 0), the result of the function will be -0 (minus zero). In this case the test with parameters a=5 and b = 0 fails.
But it shouldn't fail, because as we can see on screenshot (please, try it in your chrome console 0 === -0):
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.
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.
But we have successful travis build for such solution here for example:
#928
https://travis-ci.org/github/AleshaKolesnikov/js-assignments/builds/719550067
Please, try to find differences.
May be node versions, travis.yml
task/02-numbers-tasks.js
Outdated
const vectorProductX = Math.sqrt((x1 * x1) + (y1 * y1)); | ||
const vectorProductY = Math.sqrt((x2 * x2) + (y2 * y2)); |
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.
We can use Math.hypot here
task/03-date-tasks.js
Outdated
const formatToThreeDigit = (number) => number < 10 | ||
? `00${number}` | ||
: number > 10 && number < 100 | ||
? `0${number}` | ||
: number; |
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.
Please,avoid this code style, if-else is more readable than multiple conditional operators ? :
task/04-arrays-tasks.js
Outdated
*/ | ||
function getItemsSum(arr) { | ||
throw new Error('Not implemented'); | ||
return (arr.length) ? arr.reduce((sum, currentItem) => sum += currentItem) : 0; |
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.
redundant logic, we can use just reduce with initial value 0
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce
task/04-arrays-tasks.js
Outdated
*/ | ||
function getFalsyValuesCount(arr) { | ||
throw new Error('Not implemented'); | ||
return (arr.length) ? arr.reduce((sum, currentItem) => (currentItem) ? sum += 0 : sum += 1, 0) : 0; |
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.
We can rework this line without ternary operators.
task/04-arrays-tasks.js
Outdated
*/ | ||
function findAllOccurences(arr, item) { | ||
throw new Error('Not implemented'); | ||
return arr.reduce((counter, currentItem) => (currentItem === item) ? counter += 1 : counter, 0); |
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.
We can rework this line without ternary operators.
task/04-arrays-tasks.js
Outdated
throw new Error('Not implemented'); | ||
return arr.sort((a, b) => (a.country > b.country) ? 1 : | ||
(a.country < b.country) ? -1 : | ||
(a.country === b.country) ? (a.city > b.city) ? 1 : | ||
(a.city < b.city) ? -1 : 0 : 0 |
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.
Please, avoid this code style, if-else is more readable than multiple conditional operators ? :
https://travis-ci.org/github/AlexanderLH/js-assignments/builds