2020-10-06 23:10:08 +05:30

1.7 KiB

id, challengeType, videoUrl, title
id challengeType videoUrl title
596fda99c69f779975a1b67d 5 计算子字符串的出现次数

Description

任务:

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

该函数应该有两个参数:

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

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

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

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

Instructions

Tests

tests:
  - text: <code>countSubstring</code>是一个函数。
    testString: assert(typeof countSubstring === 'function');
  - text: <code>countSubstring("the three truths", "th")</code>应该返回<code>3</code> 。
    testString: assert.equal(countSubstring(testCases[0], searchString[0]), results[0]);
  - text: <code>countSubstring("ababababab", "abab")</code>应返回<code>2</code> 。
    testString: assert.equal(countSubstring(testCases[1], searchString[1]), results[1]);
  - text: <code>countSubstring("abaabba*bbaba*bbab", "a*b")</code>应返回<code>2</code> 。
    testString: assert.equal(countSubstring(testCases[2], searchString[2]), results[2]);

Challenge Seed

function countSubstring (str, subStr) {
  // Good luck!
  return true;
}

After Test

console.info('after the test');

Solution

// solution required

/section>