noclew/02_assignCentroids.js
// loop through data points and assign closest centroid
loop through data points and assign closest centroid
loop through data points and assign closest centroid
function assignCentroids(means) {
    data.forEach(function(el){
        var dist = means.map(function(mean){
            var dx = el.x - mean.x;
            var dy = el.y - mean.y;
            return Math.sqrt( dx * dx + dy * dy);
        });
        var minDist = Math.min.apply(null, dist);
        el.centroid = dist.indexOf(minDist);
    });
}
function assignCentroids ( means ) { data . forEach ( function ( el ) { var dist = means . map ( function ( mean ) { var dx = el . x - mean . x ; var dy = el . y - mean . y ; return Math . sqrt ( dx * dx + dy * dy ) ; } ) ; var minDist = Math . min . apply ( null , dist ) ; el . centroid = dist . indexOf ( minDist ) ; } ) ; }
loop through data points and assign closest centroid
loop through data points and assign closest centroid
//loop through cents //find mean dist //index position