-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththe-hashtag-generator.js
36 lines (33 loc) · 1.08 KB
/
the-hashtag-generator.js
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
28
29
30
31
32
33
34
35
36
/*
INSTRUCTIONS
=============================================================
The marketing team is spending way too much time typing in hashtags.
Let's help them with out own Hashtag Generator!
Here's the deal:
It must start with a hashtag (#).
All words must have their first letter capitalized.
If the final result is longer than 140 chars it must return false.
If the input or the result is an empty string it must return false.
Examples
" Hello there thanks for trying my Kata" => "#HelloThereThanksForTryingMyKata"
" Hello World " => "#HelloWorld"
"" => false
*/
/*
MY SOLUTION
*/
function generateHashtag (str) {
let formattedStr = str.trim();
formattedStr = formattedStr.split(' ');
if(formattedStr.length == 0 || formattedStr[0] == '') {
return false;
}
let answer = '#';
for(let i = 0; i < formattedStr.length; i++) {
answer = answer + formattedStr[i].charAt(0).toUpperCase() + formattedStr[i].substring(1);
}
if(answer.length > 140) {
return false;
}
return answer;
}