Tiny performance improvement by not compiling regular expression each time (#3479)

This commit is contained in:
Nazar Mokrynskyi
2017-11-07 16:28:18 +02:00
committed by John-David Dalton
parent 424d9fc34e
commit e23c874272

View File

@@ -1,5 +1,7 @@
import words from './words.js' import words from './words.js'
const reQuotes = /['\u2019]/g
/** /**
* Converts `string`, as space separated words, to lower case. * Converts `string`, as space separated words, to lower case.
* *
@@ -20,7 +22,7 @@ import words from './words.js'
* // => 'foo bar' * // => 'foo bar'
*/ */
const lowerCase = (string) => ( const lowerCase = (string) => (
words(`${string}`.replace(/['\u2019]/g, '')).reduce((result, word, index) => ( words(`${string}`.replace(reQuotes, '')).reduce((result, word, index) => (
result + (index ? ' ' : '') + word.toLowerCase() result + (index ? ' ' : '') + word.toLowerCase()
), '') ), '')
) )