javascript string slice time complexity