@@ -1516,3 +1516,47 @@ const maximumWealth = accounts => {
1516
1516
---
1517
1517
1518
1518
** [ ⬆ Back to Top] ( #javascript-coding-challenges-for-beginners ) **
1519
+
1520
+ ## 46. The Hashtag Generator
1521
+
1522
+ 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:
1523
+
1524
+ - It must start with a hashtag ` # `
1525
+ - All words must have their first letter capitalized.
1526
+ - If the final result is longer than 140 chars it must return ` false ` .
1527
+ - If the input or the result is an empty string it must return ` false ` .
1528
+
1529
+ ``` js
1530
+ const generateHashtag = str => {
1531
+ // Your solution
1532
+ };
1533
+
1534
+ console .log (generateHashtag (' JavaScript' )); // "#JavaScript"
1535
+ console .log (generateHashtag (' Do We have A Hashtag' )); // "#DoWeHaveAHashtag"
1536
+ console .log (generateHashtag (' ' )); // false
1537
+ console .log (generateHashtag (' ' )); // false
1538
+ console .log (generateHashtag (' a' .repeat (140 ))); // false
1539
+ console .log (generateHashtag (' a' .repeat (139 ))); // #Aaaaaaa...
1540
+ console .log (generateHashtag (' coding' + ' ' .repeat (140 ) + ' for life' )); // "#CodingForLife")
1541
+ console .log (generateHashtag (' ' .repeat (200 ))); // false
1542
+ ```
1543
+
1544
+ <details ><summary >Solution</summary >
1545
+
1546
+ ``` js
1547
+ const generateHashtag = str => {
1548
+ let hashtag = str
1549
+ .split (' ' )
1550
+ .reduce (
1551
+ (tag , word ) => tag + word .charAt (0 ).toUpperCase () + word .slice (1 ),
1552
+ ' #'
1553
+ );
1554
+ return hashtag .length === 1 || hashtag .length > 140 ? false : hashtag;
1555
+ };
1556
+ ```
1557
+
1558
+ </details >
1559
+
1560
+ ---
1561
+
1562
+ ** [ ⬆ Back to Top] ( #javascript-coding-challenges-for-beginners ) **
0 commit comments