#1 4 task aleksey prusevich - #908
Conversation
vramaniuk
left a comment
There was a problem hiding this comment.
I'll mark the PR as "Draft", please click "ready for review" when it will be finished. Thank you!
| */ | ||
| function getDistanceBetweenPoints(x1, y1, x2, y2) { | ||
| throw new Error('Not implemented'); | ||
| return Math.sqrt(Math.pow((x1 - x2), 2) + Math.pow((y1 - y2), 2)); |
There was a problem hiding this comment.
Please, improve using Math.hypot
| */ | ||
| function getRectangleArea(width, height) { | ||
| throw new Error('Not implemented'); | ||
| return width*height; |
There was a problem hiding this comment.
Please, spaces between operators
| */ | ||
| function getAngleBetweenVectors(x1, y1, x2, y2) { | ||
| throw new Error('Not implemented'); | ||
| return Math.acos((x1 * x2 + y1 * y2) / (Math.sqrt(Math.pow(x1, 2) + Math.pow(y1, 2) ) * Math.sqrt(Math.pow(x2, 2) + Math.pow(y2, 2)))); |
There was a problem hiding this comment.
We can improve it using Math.hypot
| */ | ||
| function getParallelipidedDiagonal(a,b,c) { | ||
| throw new Error('Not implemented'); | ||
| return Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) + Math.pow(c, 2)); |
| return (+year % 4 != 0) ? false : | ||
| (+year % 100 != 0) ? true : | ||
| (+year % 400 != 0) ? false : true; |
There was a problem hiding this comment.
"operator !== is always preferable
sometimes ''!=' may cause an error
(check at console :
'0' != 0
and '0' !== 0)"
| */ | ||
| function removeFalsyValues(arr) { | ||
| throw new Error('Not implemented'); | ||
| return arr.filter(arr => Boolean(arr) == true ); |
There was a problem hiding this comment.
arr is unsuatable name in this case , because originally callback may contain el,idx,arr
arr.filter(callback(element[, index, [array]])[, thisArg])
| */ | ||
| function get3TopItems(arr) { | ||
| throw new Error('Not implemented'); | ||
| return arr.splice(-3).reverse(); |
There was a problem hiding this comment.
It will not work if initial array is not sorted. Please, make the solution more universal. Add sort method
| throw new Error('Not implemented'); | ||
| let count = 0; | ||
| arr.map(function(element) { | ||
| if (typeof element == "number" && element > 0) |
There was a problem hiding this comment.
"operator === is always preferable
sometimes ''==' may cause an error
(check at console :
'0' == 0
and '0' === 0)"
| throw new Error('Not implemented'); | ||
| let count = 0; | ||
| arr.map((element) => { | ||
| if (Boolean(element) == false) |
There was a problem hiding this comment.
if (!element) wiil also work
Please, see https://javascript.info/logical-operators
| let str = ''; | ||
| arr.map((element, index) => { | ||
| if (index + 1 != arr.length) | ||
| { | ||
| str = str + element + ','; | ||
| } | ||
| else | ||
| { | ||
| str = str + element; | ||
| } | ||
| return element; | ||
| }); | ||
|
|
||
| return str; |
There was a problem hiding this comment.
Please, solve it using Array.prototype.join method
https://travis-ci.org/github/AlekseyPrusevich/js-assignments/builds/706748378