Update snippets/toTitleCase.md

Co-Authored-By: ccjmne <ccjmne@gmail.com>
This commit is contained in:
Robert Mennell
2018-10-19 17:58:40 +02:00
committed by GitHub
parent 42646e7453
commit 5316f4e8b4

View File

@ -7,7 +7,7 @@ Break the string into words, using a regexp, and combine them capitalizing the f
```js
const toTitleCase = str => str
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
.map(x => x.charAt(0).toUpperCase() + x.slice(1).toLowerCase())
.map(x => x.charAt(0).toUpperCase() + x.slice(1))
.join(' ');
```