(str, substring)
| 9 | */ |
| 10 | |
| 11 | const countSubstrings = (str, substring) => { |
| 12 | if (typeof str !== 'string' || typeof substring !== 'string') { |
| 13 | throw new TypeError('Argument should be string') |
| 14 | } |
| 15 | |
| 16 | if (substring.length === 0) return str.length + 1 |
| 17 | |
| 18 | let count = 0 |
| 19 | let position = str.indexOf(substring) |
| 20 | |
| 21 | while (position > -1) { |
| 22 | count++ |
| 23 | position = str.indexOf(substring, position + 1) |
| 24 | } |
| 25 | |
| 26 | return count |
| 27 | } |
| 28 | |
| 29 | export { countSubstrings } |
no test coverage detected