Skip to content

Instantly share code, notes, and snippets.

@jonaed1230
Created March 17, 2020 06:44
Show Gist options
  • Save jonaed1230/d3087bbb4ee55f1240a9ac82a044f83d to your computer and use it in GitHub Desktop.
Save jonaed1230/d3087bbb4ee55f1240a9ac82a044f83d to your computer and use it in GitHub Desktop.
function generateHashtag (str) {
// remove unnecessary spaces and make words capitalize
function capitaLize(string) {
if (string) {
return string.replace(/^./, string[0].toUpperCase());
}
}
// remove extra spaces from both sides of a string.
const actualString = str.trim();
if (actualString) {
let arr = actualString.split(' ').map(word => capitaLize(word));
const hashTag = "#"+arr.join('');
// if the string length is till 140 chars long take it otherwise return false
if (hashTag.length < 141) {
return hashTag;
}
return false;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment