From 802f25f78c32b011b1fe50be0719acdcc167c711 Mon Sep 17 00:00:00 2001 From: michaeltomasik Date: Mon, 18 Feb 2019 19:12:26 +0100 Subject: [PATCH] Add The hashtag generator --- theHashtagGenerator.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 theHashtagGenerator.js diff --git a/theHashtagGenerator.js b/theHashtagGenerator.js new file mode 100644 index 0000000..7d18705 --- /dev/null +++ b/theHashtagGenerator.js @@ -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; +} \ No newline at end of file