Created
September 25, 2017 22:47
-
-
Save alex-cory/4d1ce00549b72f06fa3d3069904ebd2d to your computer and use it in GitHub Desktop.
Cool strip function. strip('cool').from('coolio') using dynamic regex
This file contains hidden or 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
const strip = toRemove => ({ | |
from: str => { | |
const pattern = `(${toRemove.split('').join(')(')})` | |
return str.replace(RegExp(pattern, 'ig'), c => '') | |
} | |
}) | |
strip('cool').from('coolio') // io |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment