Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. const emojiRegex = require('emoji-regex');
  2. const regex = emojiRegex();
  3.  
  4. const string = "This string has emoji 👩 and 👩🏿 modified emoji and supermodiied emoji 💂🏾‍♀️";
  5.  
  6. function stringReverse(string) {
  7.  
  8. let match;
  9. const emojis = [];
  10. const separator = `unique_separator_${Math.random()}`;
  11. const reversedSeparator = [...separator].reverse().join('');
  12.  
  13. while (match = regex.exec(string)) {
  14. emojis.push(emoji);
  15. }
  16.  
  17. return [...string.replace(regex, separator)].reverse().join('').replace(new RegExp(reversedSeparator, 'gm'), () => emojis.pop());
  18.  
  19. }
  20.  
  21. console.log(string); // This string has emoji 👩 and 👩🏿 modified emoji and supermodiied emoji 💂🏾‍♀️
  22. console.log(stringReverse(string)); // 💂🏾‍♀️ ijome deiidomrepus dna ijome deifidom 👩🏿 dna 👩 ijome sah gnirts sihT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement