Added capitalize first letter of every word

This commit is contained in:
Blake Callens
2017-12-11 14:25:45 -05:00
committed by GitHub
parent d2719d8a2a
commit 78d1efe512

View File

@ -11,6 +11,7 @@
* [Anagrams of string (with duplicates)](#anagrams-of-string-with-duplicates)
* [Average of array of numbers](#average-of-array-of-numbers)
* [Capitalize first letter](#capitalize-first-letter)
* [Capitalize first letter of every word](#capitalize-first-letter-of-every-word)
* [Count occurences of a value in array](#count-occurences-of-a-value-in-array)
* [Current URL](#current-url)
* [Curry](#curry)
@ -79,6 +80,14 @@ Use `toUpperCase()` to capitalize first letter, `slice(1)` to get the rest of th
var capitalize = str => str[0].toUpperCase() + str.slice(1);
```
### Capitalize first letter of every word
Use `replace()` to match the first character of each word and `toUpperCase()` to capitalize it.
```js
var capitalizeEveryWord = str => str.replace(/\b[a-z]/g, char => char.toUpperCase());
```
### Count occurences of a value in array
Use `filter()` to create an array containing only the items with the specified value, count them using `length`.