@DrCode said:
This is a really nice approach, readable and
performant, and it will work well after you debug it. MAX_INDEX
is misnamed; it's actually the length of the array, not the maximum
index. So s > MAX_INDEX is the wrong condition; it should
either be s >= MAX_INDEX, or just s >= sc.length, which would
have avoided the issue (the array always knows its length; your
variable may or may not be right, and in this case it's wrong).
Well, let's not argue about the naming of MAX_INDEX, it's not the ideal
name, but what do you expect when writing sample code in a web form
editor within a few seconds? Same goes for the off-by-one error, where
you are certainly correct, that it should have been s >= MAX_INDEX.
However, using MAX_INDEX instead of sc.length was done intentionally to
achieve best performance. (see above point a) ). And for the missing
semicolons, those are cut&paste-replicated typos I overlooked.
Anyway, thanks for debugging my code, it seems at least one person took
the time to read my post.
cu