What is the most efficient way to replace text like :) -> .
So, assume I have a text like "Hello :) my name is Alex". I should convert the text into "Hello my name is Alex"
I solved this issue with help of lodash utility library.
const replaceStringWithEmoji = (string) => {
const emojiMap = {
':)': '',
':(': '',
':D': '',
';(': '',
':O': '',
';)': '',
'8)': '',
'>:@': '',
};
const emojis = [...Object.keys(emojiMap)];
return _.join(_.map(_.split(string, ' '), (s) => {
if (_.includes(emojis, s)) {
return emojiMap[s];
}
return s;
}), ' ');
};
There has to be a better way of doing it. Maybe with Regex?
Short return
return _.join(_.map(_.split(string, ' '), s => _.includes(emojis, s) ? emojiMap[s] : s), ' ');