From cd8259cb4e883cd3e1855d66045a143e5fff8167 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 f94f33ccb9e..74ae5f3c991 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -213,7 +213,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 @@ -265,7 +265,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' } ``` @@ -289,7 +289,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; }