Javascript implementation of k-means algorithm