-
Notifications
You must be signed in to change notification settings - Fork 0
Adding manhattan-distance #30
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?
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 @@ | ||
| This math algorithm is to calculate the manhattan distance with 4 variable key in by user | ||
|
|
||
| Point 1 (x[i], y[i]) | ||
| Point 2 (x[j], y[j]) | ||
|
|
||
| Then they will perform this calculation | ||
| (Math.abs(x[i] - x[j]) + Math.abs(y[i] - y[j])) | ||
|
|
||
| To obtain the result |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,7 @@ | ||||||
| import manhattanDistance from '../manhattanDistance'; | ||||||
|
|
||||||
| describe('manhattanDistance', () => { | ||||||
| it('should calculate the manhattan distance', () => { | ||||||
| expect(manhattanDistance(1,5,1,8)).toEqual(1); | ||||||
| }) | ||||||
|
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. Codacy has a fix for the issue: Expected indentation of 2 spaces but found 4.
Suggested change
|
||||||
| }) | ||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,19 @@ | ||||||||||
| //This function is calculate the manhattan 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. Codacy has a fix for the issue: Expected exception block, space or tab after '//' in comment.
Suggested change
|
||||||||||
| /** | ||||||||||
|
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. Codacy has a fix for the issue: Trailing spaces not allowed.
Suggested change
|
||||||||||
| * @param {string} x | ||||||||||
| * @param {string} y | ||||||||||
| * @return {string} | ||||||||||
| */ | ||||||||||
| export default function manhattanDistance(x, y) { | ||||||||||
|
|
||||||||||
| let SumOfManhattanDistance = 0; | ||||||||||
|
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. Codacy has a fix for the issue: Expected indentation of 2 spaces but found 0.
Suggested change
|
||||||||||
|
|
||||||||||
| for (let i = 0; i < x.length; i++){ | ||||||||||
|
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. Codacy has a fix for the issue: Expected indentation of 2 spaces but found 0.
Suggested change
|
||||||||||
| for (let j = 0; j < x[i].length ; j++){ | ||||||||||
|
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. Codacy has a fix for the issue: Unexpected whitespace before semicolon.
Suggested change
|
||||||||||
| //Compute the result of the Manhattan 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. Codacy has a fix for the issue: Expected exception block, space or tab after '//' in comment.
Suggested change
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. Codacy has a fix for the issue: Expected indentation of 6 spaces but found 1 tab.
Suggested change
|
||||||||||
| SumOfManhattanDistance += (Math.abs(x[i] - x[j]) + Math.abs(y[i] - y[j])); | ||||||||||
|
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. Codacy has a fix for the issue: Expected indentation of 6 spaces but found 1 tab.
Suggested change
|
||||||||||
| } | ||||||||||
|
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. Codacy has a fix for the issue: Expected indentation of 4 spaces but found 1 tab.
Suggested change
|
||||||||||
| } | ||||||||||
| //Send the result back to the main function | ||||||||||
|
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. Codacy has a fix for the issue: Expected exception block, space or tab after '//' in comment.
Suggested change
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. Codacy has a fix for the issue: Expected indentation of 2 spaces but found 0.
Suggested change
|
||||||||||
| return SumOfManhattanDistance; | ||||||||||
|
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. Codacy has a fix for the issue: Trailing spaces not allowed.
Suggested change
|
||||||||||
| } | ||||||||||
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.
Codacy has a fix for the issue: A space is required after ','.