Skip to content

Instantly share code, notes, and snippets.

@ceci21
Last active March 12, 2021 21:51
Show Gist options
  • Save ceci21/e6118a1d477e0838e8b7fa5bc482deb4 to your computer and use it in GitHub Desktop.
Save ceci21/e6118a1d477e0838e8b7fa5bc482deb4 to your computer and use it in GitHub Desktop.
consider these words before you make your next bropost on linkedin
const custom_text = `I know, I know. But for as weird-sounding as salmon burgers are, they are so extremely good. We’re talking crispy outsides, flaky insides, and a perfect golden color, not to mention lots of nutrition, THANK YOU SALMON. They are also easy to make and require (usually) minimal, if not zero, grocery shopping, assuming you keep a decently stocked pantry. I love, love, love these crispy pan-fried little guys.`;
const starters = [
"They fired me.",
"He wasn't fit for the job. \n\nHere's why.",
"I fired the best employee on the team.",
"I didn't get the job.",
"Against all odds, she got the job.",
"Despite being a parent of 29 kids, he didn't let that get in the way of his meetings as a Chief Semantics Officer.",
];
const middles = [
"There were tears.",
"There was hardship.",
"There wasn't anything on earth to stop them from having the best job in the whole continent.",
"For breakfast, instant noodles. For lunch, air.",
"But one phone call changed everything.",
"Here's why.",
"Love never got in the way.",
"The dog saved the day. Or so they thought.",
];
const endings = [
"So with that, I leave you with this word of advice:" /* this is the second to last line */,
"Consider this the next time you consider firing your employees.",
"What do you think?",
"Have you ever had this experience? Leave a comment below.",
];
const generator = (post) => {
const start_i = Math.floor(Math.random() * starters.length);
const end_i = Math.floor(Math.random() * endings.length);
const num_middles = Math.ceil(Math.random() * middles.length);
let start_placement = 0;
let end_placement = 0;
let middles_counter = 0;
if (end_i === 0) {
end_placement = 1;
}
const result = [];
result.push(starters[start_i]);
let j = 0;
while (middles_counter < num_middles) {
const random_middle = middles[Math.floor(Math.random() * middles.length)];
if (!result.includes(random_middle)) {
result.push(random_middle);
middles_counter++;
}
}
const lines = post.split(/\. |\? |\! |\... /);
for (let i = 0; i < lines.length; i++) {
result.push(lines[i]);
if (i === lines.length - 1 - end_placement - 1) {
result.push(endings[end_i]);
}
}
return result.join("\n\n");
};
console.log(generator(custom_text)); // Testing with custom text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment