@ -24,7 +24,7 @@ Here's what you can do to help:
|
|||||||
- Follow snippet descriptions with an empty line.
|
- Follow snippet descriptions with an empty line.
|
||||||
- **Snippet code** must be enclosed inside ` ```js ` and ` ``` `.
|
- **Snippet code** must be enclosed inside ` ```js ` and ` ``` `.
|
||||||
- Remember to start your snippet's code on a new line below the opening backticks.
|
- 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.
|
- 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.
|
- 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.
|
- 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 your function takes no arguments.
|
||||||
- Use `_` if an argument inside some function (e.g. `Array.reduce()`) is not used anywhere in your code.
|
- 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.
|
- 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.
|
- 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.
|
- Always use soft tabs (2 spaces), never hard tabs.
|
||||||
- Omit curly braces (`{` and `}`) whenever possible.
|
- Omit curly braces (`{` and `}`) whenever possible.
|
||||||
|
|||||||
16
README.md
16
README.md
@ -110,6 +110,7 @@
|
|||||||
* [`anagrams`](#anagrams)
|
* [`anagrams`](#anagrams)
|
||||||
* [`capitalize`](#capitalize)
|
* [`capitalize`](#capitalize)
|
||||||
* [`capitalizeEveryWord`](#capitalizeeveryword)
|
* [`capitalizeEveryWord`](#capitalizeeveryword)
|
||||||
|
* [`countVowels`](#countvowels)
|
||||||
* [`escapeRegExp`](#escaperegexp)
|
* [`escapeRegExp`](#escaperegexp)
|
||||||
* [`fromCamelCase`](#fromcamelcase)
|
* [`fromCamelCase`](#fromcamelcase)
|
||||||
* [`reverseString`](#reversestring)
|
* [`reverseString`](#reversestring)
|
||||||
@ -1452,6 +1453,21 @@ const capitalizeEveryWord = str => str.replace(/\b[a-z]/g, char => char.toUpperC
|
|||||||
|
|
||||||
[⬆ back to top](#table-of-contents)
|
[⬆ 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
|
### escapeRegExp
|
||||||
|
|
||||||
Escapes a string to use in a regular expression.
|
Escapes a string to use in a regular expression.
|
||||||
|
|||||||
@ -135,6 +135,7 @@
|
|||||||
</h3><a class="sublink-1" href="#anagrams">anagrams</a>
|
</h3><a class="sublink-1" href="#anagrams">anagrams</a>
|
||||||
<a class="sublink-1" href="#capitalize">capitalize</a>
|
<a class="sublink-1" href="#capitalize">capitalize</a>
|
||||||
<a class="sublink-1" href="#capitalizeeveryword">capitalizeEveryWord</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="#escaperegexp">escapeRegExp</a>
|
||||||
<a class="sublink-1" href="#fromcamelcase">fromCamelCase</a>
|
<a class="sublink-1" href="#fromcamelcase">fromCamelCase</a>
|
||||||
<a class="sublink-1" href="#reversestring">reverseString</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 => str.replace(/\b[a-z]/g, char => char.toUpperCase());
|
<pre><code class="language-js">const capitalizeEveryWord = str => str.replace(/\b[a-z]/g, char => char.toUpperCase());
|
||||||
// capitalizeEveryWord('hello world!') -> 'Hello World!'
|
// capitalizeEveryWord('hello world!') -> 'Hello World!'
|
||||||
</code></pre>
|
</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 =>
|
||||||
|
return (str.match(/[aeiou]/ig) || []).length;
|
||||||
|
// countVowels('foobar') -> 3
|
||||||
|
// countVowels('gym') -> 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">
|
</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>Escapes a string to use in a regular expression.</p>
|
||||||
<p>Use <code>replace()</code> to escape special characters.</p>
|
<p>Use <code>replace()</code> to escape special characters.</p>
|
||||||
|
|||||||
11
snippets/countVowels.md
Normal file
11
snippets/countVowels.md
Normal 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
|
||||||
|
```
|
||||||
@ -15,6 +15,7 @@ collatz:math
|
|||||||
compact:array
|
compact:array
|
||||||
compose:function
|
compose:function
|
||||||
countOccurrences:array
|
countOccurrences:array
|
||||||
|
countVowels:string
|
||||||
currentURL:browser
|
currentURL:browser
|
||||||
curry:function
|
curry:function
|
||||||
deepFlatten:array
|
deepFlatten:array
|
||||||
|
|||||||
Reference in New Issue
Block a user