Advertisement
TZinovieva

Count String Occurrences JS Fundamentals

Mar 6th, 2023
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function countStringOccurrences(text, word) {
  2.     let words = text.split(' ');
  3.     let wordCounter = 0;
  4.     for (let el of words) {
  5.         if (el === word) {
  6.             wordCounter++
  7.         }
  8.     }
  9.     console.log(wordCounter);
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement