Guest User

Untitled

a guest
Jul 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. /**
  2. * Adds "\s* betweek each character of the string
  3. * Used to generate regexp with matches with or without spaces
  4. *
  5. * @example
  6. * // returns "h\s*e\s*l\s*l\s*o"
  7. * addSpaces("hello");
  8. * @returns {String} Returns the string processed.
  9. */
  10. function addSpaces (word) {
  11. return [...word].map((e, i) => i < word.length - 1 ? [e, '\\s*'] : [e]).reduce((a, b) => a.concat(b)).join('')
  12. }
Add Comment
Please, Sign In to add comment