S-Means clustering in javascript