some algorithms done in js