Last active
January 1, 2019 01:25
-
-
Save rauschma/cd8e51f512d374a9f3a3dfe4906c23b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add flag 'g' if it isn’t there, yet | |
// Solution 1 | |
let cloneFlags = regExp.flags; | |
if (!cloneFlags.includes('g')) { | |
cloneFlags += 'g'; | |
} | |
// Solution 2 | |
const cloneFlags = regExp.flags.includes('g') | |
? regExp.flags | |
: regExp.flags + 'g'; | |
// Solution 3 | |
const f = regExp.flags; | |
const cloneFlags = f.includes('g') ? f : f+'g'; | |
// Solution 4 | |
const cloneFlags = [...new Set(regExp.flags + 'g')].join(''); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment