Skip to content

Instantly share code, notes, and snippets.

@rauschma
Last active January 1, 2019 01:25
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rauschma/cd8e51f512d374a9f3a3dfe4906c23b2 to your computer and use it in GitHub Desktop.
Save rauschma/cd8e51f512d374a9f3a3dfe4906c23b2 to your computer and use it in GitHub Desktop.
// 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