Updated distance to use Math.hypot()
This commit is contained in:
@ -118,11 +118,10 @@ var difference = (arr, values) =>
|
|||||||
|
|
||||||
### Distance between two points
|
### 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
|
```js
|
||||||
var distance = (x0, y0, x1, y1) =>
|
const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
|
||||||
Math.sqrt(Math.pow(x1-x0, 2) + Math.pow(y1 - y0, 2))
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Escape regular expression
|
### Escape regular expression
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
### Distance between two points
|
### 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
|
```js
|
||||||
var distance = (x0, y0, x1, y1) =>
|
const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
|
||||||
Math.sqrt(Math.pow(x1-x0, 2) + Math.pow(y1 - y0, 2))
|
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user