algorithams in javascripts