function containsPunctuation(word)
{
var punctuation = [";", "!", ".", "?", ",", "-"];
for(var i = 0; i < punctuation.length; i++)
{
if(word.indexOf(punctuation[i]) !== -1)
{
return true;
}
}
return false;
}
function isStopWord(word, stopWords)
{
for (var i = 0; i < stopWords.length; i += 1)
{
var stopWord = stopWords[i];
if ((containsPunctuation(word)) && (word.indexOf(stopWord) === 0) && (word.length === stopWord.length + 1))
{
return true;
}
else if (word === stopWord)
{
return true;
}
}
return false;
}
В блоке, как containsPunctuation(word) && (word.indexOf(stopWord) === 0
? Может ли кто-нибудь объяснить, почему они равны нулю?Может кто-нибудь объяснить мне, как функция может равняться 0?
Я также не знаю, почему используется (word.length === stopWord.length + 1)
.
Каковы входные значения? – Sparrow
Это было дано («лесной тупик, бегун», [«the»]) –