-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday_29.js
More file actions
29 lines (23 loc) · 808 Bytes
/
day_29.js
File metadata and controls
29 lines (23 loc) · 808 Bytes
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
// Mumbling
// Each char becomes n*chars where n is the index + 1, and the first char is capitalized divided by - instead of space.
// Only alphabets are passed as arguments for the accum(s) funciton
// Example: accum("ZpglnRxqenU") should return "Z-Pp-Ggg-Llll-Nnnnn-Rrrrrr-Xxxxxxx-Qqqqqqqq-Eeeeeeeee-Nnnnnnnnnn-Uuuuuuuuuuu
function accum(s) {
// your code goes below
let k, res = '';
strChar = s.toLowerCase().split('');
for(let i=0; i<strChar.length; i++) {
k = i+1;
let temp = '';
while(k>0) {
temp += strChar[i];
k--;
}
temp = capitalFirstLetter(temp);
res += `${temp}-`
}
return res.slice(0, -1);
}
function capitalFirstLetter(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}