Common, but advanced, algorithms for javascript String