-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5kyu - The Hashtag Generator.js
More file actions
28 lines (21 loc) · 977 Bytes
/
5kyu - The Hashtag Generator.js
File metadata and controls
28 lines (21 loc) · 977 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
28
// The marketing team is spending way too much time typing in hashtags.
// Let's help them with our 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
function generateHashtag(str) {
const result = str.trim().split(" ").filter(word => word.match(/[a-z]/gi)).map(word => word.replace(/ /g, '').charAt(0).toUpperCase() + word.slice(1))
if (result.toString() === "") {
return false
} if (result.join("").toString().length > 139) {
return false
} else {
return "#" + result.join('')
}
}