Merge pull request #242 from fejes713/master

Add countVowels
This commit is contained in:
Angelos Chalaris
2017-12-19 12:34:32 +02:00
committed by GitHub
5 changed files with 39 additions and 2 deletions

View File

@ -24,7 +24,7 @@ Here's what you can do to help:
- Follow snippet descriptions with an empty line.
- **Snippet code** must be enclosed inside ` ```js ` and ` ``` `.
- Remember to start your snippet's code on a new line below the opening backticks.
- Use ES6 notation to define your function. For example `const myFunction = arg1, arg2 => { }`.
- Use ES6 notation to define your function. For example `const myFunction = ( arg1, arg2 ) => { }`.
- Try to keep your snippets' code short and to the point. Use modern techniques and features. Make sure to test your code before submitting.
- All snippets must be followed by one (more if necessary) test case after the code, on a new line, in the form of a comment, along with the expected output. The syntax for this is `myFunction('testInput') -> 'testOutput'`. Use multiline comments only if necessary.
- Try to make your function name unique, so that it does not conflict with existing snippets.
@ -57,7 +57,7 @@ Here's what you can do to help:
- Use `()` if your function takes no arguments.
- Use `_` if an argument inside some function (e.g. `Array.reduce()`) is not used anywhere in your code.
- Specify default parameters for arguments, if necessary. It is preferred to put default parameters last unless you have pretty good reason not to.
- If your snippet's function takes variadic arguments, use `..args` (although in certain cases, it might be needed to use a different name).
- If your snippet's function takes variadic arguments, use `...args` (although in certain cases, it might be needed to use a different name).
- If your snippet function's body is a single statement, omit the `return` keyword and use an expression instead.
- Always use soft tabs (2 spaces), never hard tabs.
- Omit curly braces (`{` and `}`) whenever possible.

View File

@ -110,6 +110,7 @@
* [`anagrams`](#anagrams)
* [`capitalize`](#capitalize)
* [`capitalizeEveryWord`](#capitalizeeveryword)
* [`countVowels`](#countvowels)
* [`escapeRegExp`](#escaperegexp)
* [`fromCamelCase`](#fromcamelcase)
* [`reverseString`](#reversestring)
@ -1452,6 +1453,21 @@ const capitalizeEveryWord = str => str.replace(/\b[a-z]/g, char => char.toUpperC
[⬆ back to top](#table-of-contents)
### countVowels
Retuns `number` of vowels in provided string.
Use a regular expression to count number of vowels `(A, E, I, O, U)` in a `string`.
```js
const countVowels = str =>
return (str.match(/[aeiou]/ig) || []).length;
// countVowels('foobar') -> 3
// countVowels('gym') -> 0
```
[⬆ back to top](#table-of-contents)
### escapeRegExp
Escapes a string to use in a regular expression.

View File

@ -135,6 +135,7 @@
</h3><a class="sublink-1" href="#anagrams">anagrams</a>
<a class="sublink-1" href="#capitalize">capitalize</a>
<a class="sublink-1" href="#capitalizeeveryword">capitalizeEveryWord</a>
<a class="sublink-1" href="#countvowels">countVowels</a>
<a class="sublink-1" href="#escaperegexp">escapeRegExp</a>
<a class="sublink-1" href="#fromcamelcase">fromCamelCase</a>
<a class="sublink-1" href="#reversestring">reverseString</a>
@ -886,6 +887,14 @@ Omit the <code>lowerRest</code> parameter to keep the rest of the string intact,
<pre><code class="language-js">const capitalizeEveryWord = str =&gt; str.replace(/\b[a-z]/g, char =&gt; char.toUpperCase());
// capitalizeEveryWord('hello world!') -&gt; 'Hello World!'
</code></pre>
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="countvowels">countVowels</h3></div><div class="section double-padded">
<p>Retuns <code>number</code> of vowels in provided string.</p>
<p>Use a regular expression to count number of vowels <code>(A, E, I, O, U)</code> in a <code>string</code>.</p>
<pre><code class="language-js">const countVowels = str =&gt;
return (str.match(/[aeiou]/ig) || []).length;
// countVowels('foobar') -&gt; 3
// countVowels('gym') -&gt; 0
</code></pre>
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="escaperegexp">escapeRegExp</h3></div><div class="section double-padded">
<p>Escapes a string to use in a regular expression.</p>
<p>Use <code>replace()</code> to escape special characters.</p>

11
snippets/countVowels.md Normal file
View File

@ -0,0 +1,11 @@
### countVowels
Retuns `number` of vowels in provided string.
Use a regular expression to count number of vowels `(A, E, I, O, U)` in a `string`.
```js
const countVowels = str => (str.match(/[aeiou]/ig) || []).length;
// countVowels('foobar') -> 3
// countVowels('gym') -> 0
```

View File

@ -15,6 +15,7 @@ collatz:math
compact:array
compose:function
countOccurrences:array
countVowels:string
currentURL:browser
curry:function
deepFlatten:array