From 161f722d80527ef2d48477c93d26cbe7ef739425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Feje=C5=A1?= Date: Mon, 18 Dec 2017 20:07:44 +0100 Subject: [PATCH 1/4] Add countVowels --- snippets/countVowels.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 snippets/countVowels.md diff --git a/snippets/countVowels.md b/snippets/countVowels.md new file mode 100644 index 000000000..d7d98248b --- /dev/null +++ b/snippets/countVowels.md @@ -0,0 +1,12 @@ +### 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 +``` From 27a186021493f73e752113519589611417480bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Feje=C5=A1?= Date: Mon, 18 Dec 2017 20:20:24 +0100 Subject: [PATCH 2/4] Generated readme, index and tag_database for countVowels --- README.md | 16 ++++++++++++++++ docs/index.html | 9 +++++++++ tag_database | 1 + 3 files changed, 26 insertions(+) diff --git a/README.md b/README.md index c4a6765d3..3ba0a832b 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/docs/index.html b/docs/index.html index 7c2e08821..cabdd7c23 100644 --- a/docs/index.html +++ b/docs/index.html @@ -133,6 +133,7 @@ anagrams capitalize capitalizeEveryWord +countVowels escapeRegExp fromCamelCase reverseString @@ -884,6 +885,14 @@ Omit the lowerRest parameter to keep the rest of the string intact,
const capitalizeEveryWord = str => str.replace(/\b[a-z]/g, char => char.toUpperCase());
 // capitalizeEveryWord('hello world!') -> 'Hello World!'
 
+

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.

+
const countVowels = str =>
+  return (str.match(/[aeiou]/ig) || []).length;
+// countVowels('foobar') -> 3
+// countVowels('gym') -> 0
+

escapeRegExp

Escapes a string to use in a regular expression.

Use replace() to escape special characters.

diff --git a/tag_database b/tag_database index f48f069b3..9f48d15cb 100644 --- a/tag_database +++ b/tag_database @@ -15,6 +15,7 @@ collatz:math compact:array compose:function countOccurrences:array +countVowels:string currentURL:browser curry:function deepFlatten:array From 5bb17d75a34295f33ab4dc4596d26e0154644483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Feje=C5=A1?= Date: Mon, 18 Dec 2017 20:26:37 +0100 Subject: [PATCH 3/4] Fix small syntax typo --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4b1164232..ac39ceccc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. From 0cf7855879d9d68f213a4b5b443b8c2287af300e Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Tue, 19 Dec 2017 12:33:51 +0200 Subject: [PATCH 4/4] Update countVowels.md --- snippets/countVowels.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/snippets/countVowels.md b/snippets/countVowels.md index d7d98248b..bf1f536fc 100644 --- a/snippets/countVowels.md +++ b/snippets/countVowels.md @@ -5,8 +5,7 @@ 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; +const countVowels = str => (str.match(/[aeiou]/ig) || []).length; // countVowels('foobar') -> 3 // countVowels('gym') -> 0 ```