Hacker News new | past | comments | ask | show | jobs | submit login

The most appropriate behavior is implemented by regex.

Find the empty string and replace with say

  `($&)` 
where

  `$&`
refers to the captured variable, and with input

  `xyz`,
the result is

  `()x()y()z()`
With an empty input, the result is

  `()`.
The result of indexOf can consistently return the first index of the first half open subrange in a string. It just so happens that the first subrange of an empty string in an empty string is [0, 0).

The limiting case is also an interesting way to look at it:

  ()a()b()c()
  ()a()b()
  ()a()
  ()



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: