-
Notifications
You must be signed in to change notification settings - Fork 192
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
#1 4 task aleksey prusevich #908
base: master
Are you sure you want to change the base?
#1 4 task aleksey prusevich #908
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!
@@ -73,7 +73,7 @@ function getAverage(value1, value2) { | |||
* (-5,0) (10,-10) => 18.027756377319946 | |||
*/ | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, improve using Math.hypot
@@ -22,7 +22,7 @@ | |||
* 5, 5 => 25 | |||
*/ | |||
function getRectangleArea(width, height) { | |||
throw new Error('Not implemented'); | |||
return width*height; |
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, spaces between operators
@@ -111,7 +111,7 @@ function getLinearEquationRoot(a, b) { | |||
* (0,1) (1,2) => 0 | |||
*/ | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can improve it using Math.hypot
@@ -160,7 +160,7 @@ function parseNumberFromString(value) { | |||
* 1,2,3 => 3.741657386773941 | |||
*/ | |||
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)); |
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, use Math.hypot
return (+year % 4 != 0) ? false : | ||
(+year % 100 != 0) ? true : | ||
(+year % 400 != 0) ? false : true; |
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.
"operator !== is always preferable
sometimes ''!=' may cause an error
(check at console :
'0' != 0
and '0' !== 0)"
@@ -102,7 +106,7 @@ function getArrayOfStrings(arr) { | |||
* [ false, 0, NaN, '', undefined ] => [ ] | |||
*/ | |||
function removeFalsyValues(arr) { | |||
throw new Error('Not implemented'); | |||
return arr.filter(arr => Boolean(arr) == true ); |
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.
arr
is unsuatable name in this case , because originally callback may contain el,idx,arr
arr.filter(callback(element[, index, [array]])[, thisArg])
@@ -286,7 +315,7 @@ function propagateItemsByPositionIndex(arr) { | |||
* [ 10, 10, 10, 10 ] => [ 10, 10, 10 ] | |||
*/ | |||
function get3TopItems(arr) { | |||
throw new Error('Not implemented'); | |||
return arr.splice(-3).reverse(); |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, solve it using Array.prototype.join method
https://travis-ci.org/github/AlekseyPrusevich/js-assignments/builds/706748378