K means clustering in Javascript