DEV Community

Discussion on: Daily Challenge #219 - Compare Strings

Collapse
 
fluffynuts profile image
Davyd McColl • Edited

JavaScript:

function strCount(haystack, needle) {
  return (
    (haystack || "")
      .match(new RegExp(`${needle}`, "g")) || []
  ).length;
}