--- title: Count occurrences of a substring id: 596fda99c69f779975a1b67d challengeType: 5 videoUrl: '' localeTitle: 计算子字符串的出现次数 --- ## Description
任务:

创建函数或显示内置函数,以计算字符串中子字符串的非重叠出现次数。

该函数应该有两个参数:

第一个参数是要搜索的字符串,第二个参数是要搜索的子字符串。

它应该返回一个整数计数。

匹配应产生最多数量的非重叠匹配。

通常,这实质上意味着从左到右或从右到左匹配。

## Instructions
## Tests
```yml tests: - text: countSubstring是一个函数。 testString: 'assert(typeof countSubstring === "function", "countSubstring is a function.");' - text: 'countSubstring("the three truths", "th")应该返回3 。' testString: 'assert.equal(countSubstring(testCases[0], searchString[0]), results[0], "countSubstring("the three truths", "th") should return 3.");' - text: 'countSubstring("ababababab", "abab")应返回2 。' testString: 'assert.equal(countSubstring(testCases[1], searchString[1]), results[1], "countSubstring("ababababab", "abab") should return 2.");' - text: 'countSubstring("abaabba*bbaba*bbab", "a*b")应返回2 。' testString: 'assert.equal(countSubstring(testCases[2], searchString[2]), results[2], "countSubstring("abaabba*bbaba*bbab", "a*b") should return 2.");' ```
## Challenge Seed
```js function countSubstring (str, subStr) { // Good luck! return true; } ```
### After Test
```js console.info('after the test'); ```
## Solution
```js // solution required ```