Guest User

Untitled

a guest
Jun 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. /**
  2. * Simple remove word function
  3. * @param {string} string The string where the words will be removed.
  4. * @param {string|array} toRemove A single word or an array of words to remove
  5. */
  6. function removeWord(string, toRemove) {
  7. return (Array.isArray(toRemove)) ?
  8. string.replace(new RegExp('(' + toRemove.join(')|(') + ')', 'g'), '') :
  9. string.split(' ').filter(word => word !== toRemove).join(' ')
  10. }
Add Comment
Please, Sign In to add comment