JavaScript n00b here. I have the following block of code in the webpage I'm making:
for (var k = 0, n = startingText.length; k < n; ++k)
{
if (startingText[k] in map1)
++map1[startingText[k]];
else
map1[startingText[k]] = 1;
}
However, I presume this can and should be optimized. I don't want to have to call the access operator on startingText
when I'm iterating through its elements sequentially. Or does it matter? I learned C++ before I tried learning JavaScript, so my intuition says there must exist some JavaScript equivalent of iterating through the pointers to the characters of startingText
and dereferencing them to get their values.