Skip to content

Commit cd8259c

Browse files
alexweejmarco-ippolito
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 <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent 7b0ea9a commit cd8259c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

doc/api/modules.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ With the following ES Modules:
213213

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

219219
```mjs
@@ -265,7 +265,7 @@ export default class Point {
265265

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

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

291291
```mjs
292-
export function distance(a, b) { return (b.x - a.x) ** 2 + (b.y - a.y) ** 2; }
292+
export function distance(a, b) { return Math.sqrt((b.x - a.x) ** 2 + (b.y - a.y) ** 2); }
293293

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

0 commit comments

Comments
 (0)