Skip to content
Permalink
Browse files

Tiny performance improvement by not compiling regular expression each…

… time (#3479)
  • Loading branch information...
nazar-pc authored and jdalton committed Nov 7, 2017
1 parent 424d9fc commit e23c8742728455eefcc8ab1021f336e88c4f9e13
Showing with 3 additions and 1 deletion.
  1. +3 −1 lowerCase.js
@@ -1,5 +1,7 @@
import words from './words.js'

const reQuotes = /['\u2019]/g

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

0 comments on commit e23c874

Please sign in to comment.
You can’t perform that action at this time.