code: function closestPoint0d(a, x, result) {
    var d = 0.0;
    for(var i=0; i<x.length; ++i) {
      result[i] = a[i];
      var t = a[i] - x[i];
      d += t * t;
    }
    return d;
  }
docs: Closest point to a point is trivial