https://www.codewars.com/kata/52449b062fb80683ec000024
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
DESCRIPTION:
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) {
str = str.split(' ').filter(el => el !== "").map(el => el[0].toUpperCase() + el.slice(1)).join("");
return str.length === 0 || str.length >= 140 ? false : '#' + str;
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Twice as old (8 kyu) / JavaScript (0) | 2023.04.20 |
---|---|
[Codewars] Super Duper Easy (8 kyu) / JavaScript (0) | 2023.04.19 |
[Codewars] Consecutive strings (6 kyu) / JavaScript (0) | 2023.04.18 |
[Codewars] Password maker (7 kyu) / JavaScript (0) | 2023.04.18 |
[Codewars] Power (8 kyu) / JavaScript (0) | 2023.04.17 |
댓글