-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhastagGenerator.js
31 lines (23 loc) · 1.03 KB
/
hastagGenerator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* -------------------------------------------------------
* Programming Question : Hash Tag Generator
* -------------------------------------------------------
**/
// Q. You are required to implement a function generateHash that generates a hash tag from a given input string. The hash tag should be constructed.
/** steps
* First check there empty space or not and should be less than 280 . if yes then return false;
* Split the sentence into word.
* Then pick up the first letter of word using .[0].upperCase() and transform it into capital.
* Now combine remaining letters with capital letter and add with join("").
* Finally add "#" and with result. Here you will get output
**/
function generateHash(str) {
if (str.length > 280 || str.trim().length === 0) {
return false;
}
let splitStr = str.split(/\s+/);
let capCase = splitStr.map(lett => lett[0].toUpperCase() + lett.slice(1)).join("");
let hashTag = "#" + capCase;
return hashTag;
}
console.log(generateHash('My name is ganesh bardade'));