function checkForSpecialCharacters(text)
{
var specialChars = [";", "!", ".", "?", ",", "-"];
for(var i = 0; i < specialChars.length; i++)
{
if(text.indexOf(specialChars[i]) !== -1)
{
return true;
}
}
return false;
}
function isCommonWord(word, commonWords)
{
for (var i = 0; i < commonWords.length; i += 1)
{
var commonWord = commonWords[i];
if ((checkForSpecialCharacters(word)) && (word.indexOf(commonWord) === 0) && (word.length === commonWord.length + 1))
{
return true;
}
else if (word === commonWord)
{
return true;
}
}
return false;
}
In the snippet above, why does
checkForSpecialCharacters(text) && (word.indexOf(commonWord) === 0
both evaluate to zero? Can someone clarify this?
I'm also uncertain about the rationale behind using
(word.length === commonWord.length + 1)
. Why is this comparison made?