Updated distance to use Math.hypot()

This commit is contained in:
Angelos Chalaris
2017-12-12 10:52:57 +02:00
parent 6433a68f8d
commit 27c38d2f8a
2 changed files with 4 additions and 6 deletions

View File

@ -118,11 +118,10 @@ var difference = (arr, values) =>
### Distance between two points
Use `Math.pow()` and `Math.sqrt()` to calculate the Euclidean distance between two points.
Use `Math.hypot()` to calculate the Euclidean distance between two points.
```js
var distance = (x0, y0, x1, y1) =>
Math.sqrt(Math.pow(x1-x0, 2) + Math.pow(y1 - y0, 2))
const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
```
### Escape regular expression

View File

@ -1,8 +1,7 @@
### Distance between two points
Use `Math.pow()` and `Math.sqrt()` to calculate the Euclidean distance between two points.
Use `Math.hypot()` to calculate the Euclidean distance between two points.
```js
var distance = (x0, y0, x1, y1) =>
Math.sqrt(Math.pow(x1-x0, 2) + Math.pow(y1 - y0, 2))
const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
```