Skip to content

Commit 9de45cb

Browse files
alexweejtargos
authored andcommitted
doc: modules.md: fix distance definition
It's somewhat esoteric at best to define distance in terms of squared length! PR-URL: #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 a7e5ef9 commit 9de45cb

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
@@ -212,7 +212,7 @@ With the following ES Modules:
212212

213213
```mjs
214214
// distance.mjs
215-
export function distance(a, b) { return (b.x - a.x) ** 2 + (b.y - a.y) ** 2; }
215+
export function distance(a, b) { return Math.sqrt((b.x - a.x) ** 2 + (b.y - a.y) ** 2); }
216216
```
217217

218218
```mjs
@@ -264,7 +264,7 @@ export default class Point {
264264

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

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

290290
```mjs
291-
export function distance(a, b) { return (b.x - a.x) ** 2 + (b.y - a.y) ** 2; }
291+
export function distance(a, b) { return Math.sqrt((b.x - a.x) ** 2 + (b.y - a.y) ** 2); }
292292

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

0 commit comments

Comments
 (0)