2018-10-08 17:34:43 +00:00
---
title: Count occurrences of a substring
id: 596fda99c69f779975a1b67d
challengeType: 5
2018-10-10 20:20:40 +00:00
videoUrl: ''
localeTitle: Contar las apariciones de una subcadena.
2018-10-08 17:34:43 +00:00
---
## Description
2018-10-10 20:20:40 +00:00
< section id = "description" > Tarea: < p > Cree una función, o muestre una función incorporada, para contar el número de apariciones no superpuestas de una subcadena dentro de una cadena. < / p > < p > La función debe tomar dos argumentos: < / p > el primer argumento es la cadena a buscar, y el segundo una subcadena a buscar. < p > Debe devolver un número entero. < / p > < p > La coincidencia debe producir el mayor número de coincidencias no superpuestas. < / p > < p > En general, esto significa esencialmente coincidir de izquierda a derecha o de derecha a izquierda. < / p > < / section >
2018-10-08 17:34:43 +00:00
## Instructions
2018-10-10 20:20:40 +00:00
< section id = "instructions" >
2018-10-08 17:34:43 +00:00
< / section >
## Tests
< section id = 'tests' >
```yml
tests:
- text: < code > countSubstring</ code > es una función.
testString: 'assert(typeof countSubstring === "function", "< code > countSubstring< / code > is a function.");'
2018-10-10 20:20:40 +00:00
- text: '< code > countSubstring(" the three truths" , " th" )</ code > debe devolver < code > 3</ code > .'
2018-10-08 17:34:43 +00:00
testString: 'assert.equal(countSubstring(testCases[0], searchString[0]), results[0], "< code > countSubstring("the three truths", "th")< / code > should return < code > 3< / code > .");'
2018-10-10 20:20:40 +00:00
- text: '< code > countSubstring(" ababababab" , " abab" )</ code > debe devolver < code > 2</ code > .'
2018-10-08 17:34:43 +00:00
testString: 'assert.equal(countSubstring(testCases[1], searchString[1]), results[1], "< code > countSubstring("ababababab", "abab")< / code > should return < code > 2< / code > .");'
2018-10-10 20:20:40 +00:00
- text: '< code > countSubstring(" abaabba*bbaba*bbab" , " a*b" )</ code > debe devolver < code > 2</ code > .'
2018-10-08 17:34:43 +00:00
testString: 'assert.equal(countSubstring(testCases[2], searchString[2]), results[2], "< code > countSubstring("abaabba*bbaba*bbab", "a*b")< / code > should return < code > 2< / code > .");'
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
function countSubstring (str, subStr) {
// Good luck!
return true;
}
2018-10-10 20:20:40 +00:00
2018-10-08 17:34:43 +00:00
```
< / div >
### After Test
< div id = 'js-teardown' >
```js
console.info('after the test');
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
2018-10-10 20:20:40 +00:00
// solution required
2018-10-08 17:34:43 +00:00
```
< / section >