es-next-tools
Version:
A comprehensive utility library for JavaScript and TypeScript that provides a wide range of functions for common programming tasks, including mathematical operations, date manipulations, array and object handling, string utilities, and more.
13 lines (12 loc) • 368 B
JavaScript
/**
* Calculates the Euclidean distance between two points.
* @param {Point} p - The first point
* @param {Point} q - The second point.
* @returns The Euclidean distance between the two points.
* @example
* dist([1, 2], [4, 6]); // 5
*/
export function dist(p, q) {
const [px, py] = p, [qx, qy] = q;
return Math.sqrt((qx - px) ** 2 + (qy - py) ** 2);
}