Skip to content

Instantly share code, notes, and snippets.

@pirmax

pirmax/code.js Secret

Created Nov 15, 2021
Embed
What would you like to do?
function parse(string, hashtags) {
hashtags = hashtags.map((hashtag) => {
return hashtag.replace('#', '');
});
string = hashtags.reduce((acc, tag, i) =>
acc.replace(new RegExp('\\b' + tag + '\\b', 'gi'), () => {
hashtags[i] = null;
return '#' + tag;
}), string);
hashtags = hashtags.filter(Boolean);
return {string, hashtags};
}
const string = inputData.string;
const hashtags = inputData.hashtags.split(',');
const link = inputData.link;
const parsed = parse(string, hashtags);
const otherHashtags = parsed.hashtags.splice(0, 3).map((hashtag) => {
return '#' + hashtag;
});
const parts = [];
parts.push(parsed.string);
parts.push('🚀');
parts.push(otherHashtags.join(' '));
parts.push(link);
const tweet = parts.join(' ');
output = {tweet};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment