Simple swarm algorithm in javascript