diff --git a/README.md b/README.md index cb3cad760..8b75fb1f5 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/snippets/distance-between-two-points.md b/snippets/distance-between-two-points.md index f6e4eb74c..a93ca2102 100644 --- a/snippets/distance-between-two-points.md +++ b/snippets/distance-between-two-points.md @@ -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); ```