const countSubstrings = (str: string, searchValue: string) => {
        let count: number = 0,
          i: number = 0;
        while (true) {
          const r: number = str.indexOf(searchValue, i);
          if (r !== -1) [count, i] = [count + 1, r + 1];
          else return count;
        }
      };
      
      Typescript language logo

      Count substrings occurrences

      Codiga's TypeScript Recipes

      Counts the occurrences of a substring in a given string.

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.