From b6cd6b7e31301ea190dac45f876bc7da4e87f8a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20=E2=80=9Cweej=E2=80=9D=20Jones?= Date: Sun, 16 Feb 2025 18:26:30 +0000 Subject: [PATCH] doc: `modules.md`: fix `distance` definition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's somewhat esoteric at best to define distance in terms of squared length! PR-URL: https://github.com/nodejs/node/pull/57046 Reviewed-By: Rafael Gonzaga Reviewed-By: Juan José Arboleda Reviewed-By: Chengzhong Wu Reviewed-By: Joyee Cheung --- doc/api/modules.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/api/modules.md b/doc/api/modules.md index 5a332a0e8f7..9e7c2e9b099 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -217,7 +217,7 @@ With the following ES Modules: ```mjs // distance.mjs -export function distance(a, b) { return (b.x - a.x) ** 2 + (b.y - a.y) ** 2; } +export function distance(a, b) { return Math.sqrt((b.x - a.x) ** 2 + (b.y - a.y) ** 2); } ``` ```mjs @@ -269,7 +269,7 @@ export default class Point { // `distance` is lost to CommonJS consumers of this module, unless it's // added to `Point` as a static property. -export function distance(a, b) { return (b.x - a.x) ** 2 + (b.y - a.y) ** 2; } +export function distance(a, b) { return Math.sqrt((b.x - a.x) ** 2 + (b.y - a.y) ** 2); } export { Point as 'module.exports' } ``` @@ -293,7 +293,7 @@ named exports attached to it as properties. For example with the example above, ```mjs -export function distance(a, b) { return (b.x - a.x) ** 2 + (b.y - a.y) ** 2; } +export function distance(a, b) { return Math.sqrt((b.x - a.x) ** 2 + (b.y - a.y) ** 2); } export default class Point { constructor(x, y) { this.x = x; this.y = y; }