Skip to content

Instantly share code, notes, and snippets.

@alex-cory
Created September 25, 2017 22:47
Show Gist options
  • Save alex-cory/4d1ce00549b72f06fa3d3069904ebd2d to your computer and use it in GitHub Desktop.
Save alex-cory/4d1ce00549b72f06fa3d3069904ebd2d to your computer and use it in GitHub Desktop.
Cool strip function. strip('cool').from('coolio') using dynamic regex
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