k-means exercise by javascript