Added a solution/fixed stub :) (#34198)
Added a solution to the stub regardingn Javascript Algorithms And Data Structures Certification\Regular Expressions
This commit is contained in:
		
				
					committed by
					
						 Paul Gamble
						Paul Gamble
					
				
			
			
				
	
			
			
			
						parent
						
							2910a9e6ac
						
					
				
				
					commit
					ce33b6c650
				
			| @@ -3,8 +3,26 @@ title: Specify Exact Number of Matches | ||||
| --- | ||||
| ## Specify Exact Number of Matches | ||||
|  | ||||
| This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/javascript-algorithms-and-data-structures/regular-expressions/specify-exact-number-of-matches/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>. | ||||
| ### Hint 1: | ||||
| We see that the answer is simply finding 4 m's in a row. The first anwser would be to match EXACTLY 4 times the character so we shall implement as following: | ||||
| ````javascript | ||||
| let timRegex = /m{4}/;  | ||||
| ```` | ||||
| This solution is incorrect because you wont pass the final test case ("Timber" with 30 m's in it) as there are multiple times mmmm in a row of 30 m. | ||||
| You should try to get **no more than** ***(4 times m) mmmm***.  | ||||
|  | ||||
| <a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>. | ||||
| ### Hint 2: | ||||
| Based on the above I will try to specify exactly the characters before and after 4 times m! | ||||
| ***Remember:***  e.g. /b/ is a string literal for the word b so what if before and after mmmm we add ALL missing letters? | ||||
|  | ||||
|  | ||||
|  | ||||
| ### Solution | ||||
| From hint 1 we defined how to find mmmm in the timStr. From hint 2 we observe that we need to find the word Timmmmber=Tim{4}ber. | ||||
| We simpply add the exact word in our timRegex value and the final result is: | ||||
| ````javascript | ||||
| let timStr = "Timmmmber"; | ||||
| let timRegex = /Tim{4}ber/; // Change this line | ||||
| let result = timRegex.test(timStr); | ||||
| ```` | ||||
|  | ||||
| <!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds  --> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user