-
Notifications
You must be signed in to change notification settings - Fork 0
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
Create test.js #14
Create test.js #14
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function getDistance(xA, yA, xB, yB) { | ||
var xDiff:Number = xA - xB; | ||
var yDiff:Number = yA - yB; | ||
|
||
return Math.sqrt(xDiff * xDiff + yDiff * yDiff); | ||
} | ||
|
||
var distance = getDistance(0, 0, 100, 100); | ||
alert(distance); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code appears to be JavaScript function that calculates the Euclidean distance between two points specified by their x and y coordinates. The code looks straightforward and concise, and I cannot identify any obvious bug risks from it. However, there are a few suggestions for improvement:
Overall, the code seems functional and well-written, but making some minor improvements could make it even better. |
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 provided code looks good and does what it intends to do, calculate the Euclidean distance between two points. Here are a few suggestions for improvements:
Use 'let' instead of 'var': Since you're using ES6 syntax, it's better to use
let
instead ofvar
to update variable values.Type declarations: The type declarations in the function signature, "Number", are not needed as JavaScript is a dynamically typed language.
Parameter naming for readability: Consider naming your variables with more meaningful names than xA, yA, etc., to make the code easier to understand.
Floating point precision limitations: If you are working with very small distances that need high levels of precision, using a different method to calculate the distance (such as haversine formula) may be necessary.
Overall, the code looks functional and should work without problems.