[JavaScript Fundamentals] Strings and Regular Expressions - 08. Word Occurences
Здравейте колеги,
В judge системата ми дава само 20 точки .Явно нещо пропуска в условието
function occurencesWord(input) {
let text = input[0];
let word = input[1];
let count = 0;
while (text.indexOf(target) > 0) {
text = text.substring(text.indexOf(target) + 1);
count++;
}
console.log(count)
}
function countWordOccurencesInSentence(sentence, word) { sentence = String(sentence).toLowerCase() word = String(word).toLowerCase() let patternString = '\\b' + `${word}` + '\\b' let pattern = new RegExp(patternString, 'g') let matches = String(sentence).match(pattern) if (!matches) { console.log(0) } else { console.log(matches.length) } };Благодаря!