Someone often writes like this when extracting characters one by one from the beginning to the end of a string.
For example:
function rev1(str, i, ret) {
for (i = 1; i <= length(str); i++) {
ret = substr(str, i, 1) ret;
}
return ret;
}
I think don't necessarily have to use the length().
function rev2(str, ch, i, ret) {
while (ch = substr(str, ++i, 1)) {
ret = ch ret;
}
return ret;
}
It works, but is it wrong?
strwas an array, so second function will be fail