JavaScript algorithms