April 13th, 2024
What's missing in this code?
// Calculate Euclidean distance between two points in formatted string
// getEuclideanDistance('(1, 2, 3) (1, 2, 3)'); // 0
// getEuclideanDistance('(1, 2) (4, 5)'); // 4.242640687119285
// getEuclideanDistance('(3, 2, 3) (6, 2, 3)'); // 3
function getEuclideanDistance(str)
// Extract points, e.g., (1, 2) (3, 4) -> [[1, 2], [3, 4]]
const [p1, p2] = str.split(')').map((point) =>
return point.
('').
(Number).
(Number);
});
return Math.sqrt(
p1.reduce((acc, _, i) =>
return acc +
;
}, 0)
);
}
Type or select from these options