Update vectorDistance.md

This commit is contained in:
Angelos Chalaris
2019-02-25 08:30:50 +02:00
committed by GitHub
parent 2c39c8a362
commit 9426b39365

View File

@ -6,9 +6,9 @@ Use `Array.prototype.reduce()`, `Math.pow()` and `Math.sqrt()` to calculate the
```js
const vectorDistance = (...coords) => {
let pointLength = Math.trunc(coords.length / 2);
let sum = coords.slice(0, pointLength).reduce((acc, val, i) => acc + (Math.pow(val - coords[pointLength + i], 2)), 0);
return Math.sqrt(sum);
let pointLength = Math.trunc(coords.length / 2);
let sum = coords.slice(0, pointLength).reduce((acc, val, i) => acc + (Math.pow(val - coords[pointLength + i], 2)), 0);
return Math.sqrt(sum);
};
```