Created
March 17, 2020 06:44
-
-
Save jonaed1230/d3087bbb4ee55f1240a9ac82a044f83d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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