Number of Boomerangs LeetCode solution in JavaScript
1var numberOfBoomerangs = function (points) {2const POINTS_LEN = points.length;3let result = 0;45for (let i = 0; i < POINTS_LEN; i++) {6const hash = new Map();78for (let j = 0; j < POINTS_LEN; j++) {9if (i === j) continue;10const [x1, y1] = points[i];11const [x2, y2] = points[j];12const dis = Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2);13const value = hash.get(dis) ?? 0;1415if (value > 0) result += value * 2;16hash.set(dis, value + 1);17}18}1920return result;21};