Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 49678a9

Browse files
committed
Add a question
1 parent 9bdd09e commit 49678a9

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

‎README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,3 +1516,47 @@ const maximumWealth = accounts => {
15161516
---
15171517

15181518
**[⬆ 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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /