re: What happens when you IndexOf an empty string? VIEW POST

TOP OF THREAD FULL DISCUSSION
re: I'd assume that the contract of s.indexOf(b) is to return the smallest integer r such that s.substring(r, r + b.length) == b. When b is "", that r...
 

You're right, .replace("", "x") and .split("") definitely have ambiguous meanings.

One thought I just had now though is thinking what if replace was using indexOf internally. Without a special case for an empty string, it could easily get stuck replacing the character at index 0 because indexOf said it found it there.

code of conduct - report abuse