count-substring.js 242 B

12345678
  1. function countSubstring(string, substring) {
  2. const pattern = new RegExp(substring, "g");
  3. const match = string.match(pattern);
  4. return match ? match.length : 0;
  5. }
  6. module.exports = countSubstring;
  7. module.exports.default = countSubstring;