a clustering algorithm writen in javascript