Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/algorithms/math/manhattan-distance/README.md
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);

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 ','.

Suggested change
expect(manhattanDistance(1,5,1,8)).toEqual(1);
expect(manhattanDistance(1, 5,1,8)).toEqual(1);

})

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: Expected indentation of 2 spaces but found 4.

Suggested change
})
})

})
19 changes: 19 additions & 0 deletions src/algorithms/math/manhattan-distance/manhattanDistance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//This function is calculate the manhattan distance

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: Expected exception block, space or tab after '//' in comment.

Suggested change
//This function is calculate the manhattan distance
// This function is calculate the manhattan distance

/**

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: Trailing spaces not allowed.

Suggested change
/**
/**

* @param {string} x
* @param {string} y
* @return {string}
*/
export default function manhattanDistance(x, y) {

let SumOfManhattanDistance = 0;

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: Expected indentation of 2 spaces but found 0.

Suggested change
let SumOfManhattanDistance = 0;
let SumOfManhattanDistance = 0;


for (let i = 0; i < x.length; i++){

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: Expected indentation of 2 spaces but found 0.

Suggested change
for (let i = 0; i < x.length; i++){
for (let i = 0; i < x.length; i++){

for (let j = 0; j < x[i].length ; j++){

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: Unexpected whitespace before semicolon.

Suggested change
for (let j = 0; j < x[i].length ; j++){
for (let j = 0; j < x[i].length; j++){

//Compute the result of the Manhattan Distance

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: Expected exception block, space or tab after '//' in comment.

Suggested change
//Compute the result of the Manhattan Distance
// Compute the result of the Manhattan Distance

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: Expected indentation of 6 spaces but found 1 tab.

Suggested change
//Compute the result of the Manhattan Distance
//Compute the result of the Manhattan Distance

SumOfManhattanDistance += (Math.abs(x[i] - x[j]) + Math.abs(y[i] - y[j]));

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: Expected indentation of 6 spaces but found 1 tab.

Suggested change
SumOfManhattanDistance += (Math.abs(x[i] - x[j]) + Math.abs(y[i] - y[j]));
SumOfManhattanDistance += (Math.abs(x[i] - x[j]) + Math.abs(y[i] - y[j]));

}

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: Expected indentation of 4 spaces but found 1 tab.

Suggested change
}
}

}
//Send the result back to the main function

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: Expected exception block, space or tab after '//' in comment.

Suggested change
//Send the result back to the main function
// Send the result back to the main function

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: Expected indentation of 2 spaces but found 0.

Suggested change
//Send the result back to the main function
//Send the result back to the main function

return SumOfManhattanDistance;

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: Trailing spaces not allowed.

Suggested change
return SumOfManhattanDistance;
return SumOfManhattanDistance;

}