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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You're right,
.replace("", "x")
and.split("")
definitely have ambiguous meanings.One thought I just had now though is thinking what if
replace
was usingindexOf
internally. Without a special case for an empty string, it could easily get stuck replacing the character at index0
becauseindexOf
said it found it there.