-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhashtagGenerator.js
More file actions
27 lines (22 loc) · 876 Bytes
/
Copy pathhashtagGenerator.js
File metadata and controls
27 lines (22 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* 5kyu
The marketing team are spending way too much time typing in hashtags.
Let's help them with out own Hashtag Generator!
Here's the deal:
If the final result is longer than 140 chars it must return false.
If the input is a empty string it must return false.
It must start with a hashtag (#).
All words must have their first letter capitalized.
Example Input to Output:
" Hello there thanks for trying my Kata" => "#HelloThereThanksForTryingMyKata"
" Hello World " => "#HelloWorld"
*/
function generateHashtag (str) {
if (str==='') return false;
var arr = str.split(' ');
var capitalizedStr = '';
arr.forEach(function(word){
capitalizedStr += word.slice(0, 1).toUpperCase() + word.slice(1); //capitalize and add word
});
if (capitalizedStr.length > 139) return false;
else return capitalizedStr = '#' + capitalizedStr;
}