From 9f8b5ddd56e013d93a030cb069a7a300d12447d9 Mon Sep 17 00:00:00 2001 From: keithbored3310 <108907420+keithbored3310@users.noreply.github.com> Date: Sun, 7 Aug 2022 23:15:17 +0800 Subject: [PATCH] Create a Manhattan Distance Calculation Formula This is the first attempt of the Manhattan Distance Formula, feel free to update it. --- src/algorithms/math/Manhattan Distance | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/algorithms/math/Manhattan Distance diff --git a/src/algorithms/math/Manhattan Distance b/src/algorithms/math/Manhattan Distance new file mode 100644 index 00000000..6ce947a5 --- /dev/null +++ b/src/algorithms/math/Manhattan Distance @@ -0,0 +1,18 @@ +//This function is calculate the manhattan distance +@param x +@param y +@return {SumOhManhattanDistance} + +export default function manhattanDistance(x, y){ + +let SumOfManhattanDistance = 0; + +for (let i = 0; i < x.length; i++){ + for (lei j= 0; j < x[i].length ; j++){ + //Compute the result of the Manhattan Distance + SumOfManhattanDistance += (Math.abs(x[i] -x[j])+Math.abs(y[i] - y[j])); + } +} +//Send the result back to the main function +return SumOfManhattanDistance; +}