Document similarity comparison in JavaScript