src/point.js
function findClosestPoint (sources, target) {
  const distances = [];
  let minDistance;

  sources.forEach(function (source, index) {
    const d = distance(source, target);

    distances.push(d);

    if (index === 0) {
      minDistance = d;
    } else {
      minDistance = Math.min(d, minDistance);
    }
  });

  const index = distances.indexOf(minDistance);


  return sources[index];
}
function findClosestPoint (sources, target) {
  const distances = [];
  let minDistance;

  sources.forEach(function (source, index) {
    const d = distance(source, target);

    distances.push(d);

    if (index === 0) {
      minDistance = d;
    } else {
      minDistance = Math.min(d, minDistance);
    }
  });

  const index = distances.indexOf(minDistance);


  return sources[index];
}
function findClosestPoint ( sources , target ) { const distances = [ ] ; let minDistance ; sources . forEach ( function ( source , index ) { const d = distance ( source , target ) ; distances . push ( d ) ; if ( index === 0 ) { minDistance = d ; } else { minDistance = Math . min ( d , minDistance ) ; } } ) ; const index = distances . indexOf ( minDistance ) ; return sources [ index ] ; }
Returns the closest source point to a target point
given an array of source points.

@param sources An Array of source Points
@param target The target Point
@returns Point The closest point from the points array
Returns the closest source point to a target point given an array of source points .