const numberOfBoomerangs = (points) => {
let res = 0;
for(let i = 0; i < points.length; i++) {
const obj = {};
for(let j = 0; j < points.length; j++) {
if(j !== i) {
if(obj[dis(points[i], points[j])]) {
obj[dis(points[i], points[j])] += 1;
} else {
obj[dis(points[i], points[j])] = 1;
}
}
}
Object.keys(obj).forEach(item => res += obj[item] * (obj[item] - 1));
}
return res;
};
const dis = (p0, p1) => {
return Math.pow(p0[0] - p1[0], 2) + Math.pow(p0[1] - p1[1], 2);
}
来源