UNPKG

eucledian_distance

Version:

Package that calculates the eucledian distance.

21 lines 677 B
"use strict"; /** * Class to compute the eucledian distance. */ Object.defineProperty(exports, "__esModule", { value: true }); const _ = require("lodash"); class EucledianDistance { static calculate(x, y) { if (x.length !== y.length) { throw new Error("x and y must be of the same length"); } let squaredDistance = 0; _.forEach(x, (xValue, index) => { const yValue = y[index]; squaredDistance += Math.pow((xValue - yValue), 2); }); return Math.sqrt(squaredDistance); } } exports.EucledianDistance = EucledianDistance; //# sourceMappingURL=EucledianDistance.js.map