update js algorithm