Skip to content

Commit 6655ad0

Browse files
alexweejacidiney
authored andcommitted
doc: modules.md: fix distance definition
It's somewhat esoteric at best to define distance in terms of squared length! PR-URL: nodejs#57046 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent fa5f072 commit 6655ad0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

doc/api/modules.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ With the following ES Modules:
217217

218218
```mjs
219219
// distance.mjs
220-
export function distance(a, b) { return (b.x - a.x) ** 2 + (b.y - a.y) ** 2; }
220+
export function distance(a, b) { return Math.sqrt((b.x - a.x) ** 2 + (b.y - a.y) ** 2); }
221221
```
222222

223223
```mjs
@@ -269,7 +269,7 @@ export default class Point {
269269

270270
// `distance` is lost to CommonJS consumers of this module, unless it's
271271
// added to `Point` as a static property.
272-
export function distance(a, b) { return (b.x - a.x) ** 2 + (b.y - a.y) ** 2; }
272+
export function distance(a, b) { return Math.sqrt((b.x - a.x) ** 2 + (b.y - a.y) ** 2); }
273273
export { Point as 'module.exports' }
274274
```
275275

@@ -293,7 +293,7 @@ named exports attached to it as properties. For example with the example above,
293293
<!-- eslint-disable @stylistic/js/semi -->
294294

295295
```mjs
296-
export function distance(a, b) { return (b.x - a.x) ** 2 + (b.y - a.y) ** 2; }
296+
export function distance(a, b) { return Math.sqrt((b.x - a.x) ** 2 + (b.y - a.y) ** 2); }
297297

298298
export default class Point {
299299
constructor(x, y) { this.x = x; this.y = y; }

0 commit comments

Comments
 (0)