Skip to content

Commit

Permalink
Add The hashtag generator
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeltomasik committed Feb 18, 2019
1 parent 62c83b3 commit 802f25f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions theHashtagGenerator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// https://www.codewars.com/kata/the-hashtag-generator/
// 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.
function generateHashtag (str) {
const output = str.trim().length > 0 &&
'#'+str.split(' ').map(word => word && word[0].toUpperCase() + word.slice(1)).join('');
return output.length <= 140 && output;
}

0 comments on commit 802f25f

Please sign in to comment.