-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmumbling.js
More file actions
44 lines (34 loc) · 900 Bytes
/
mumbling.js
File metadata and controls
44 lines (34 loc) · 900 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
https://www.codewars.com/kata/5667e8f4e3f572a8f2000039/train/javascript
This time no story, no theory. The examples below show you how to write function accum:
Examples:
accum("abcd") -> "A-Bb-Ccc-Dddd"
accum("RqaEzty") -> "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy"
accum("cwAt") -> "C-Ww-Aaa-Tttt"
The parameter of accum is a string which includes only letters from a..z and A..Z.
*/
// First Attempt - Feb 2019
function accum(s) {
let arr = s.split('');
for (i = 0; i < arr.length; i++) {
arr[i] = arr[i].toUpperCase();
arr[i] = arr[i] + arr[i].repeat(i).toLowerCase();
}
arr = arr.join('-');
return arr;
}
// Second Attempt - Feb 2020 - Using String.split(), Array.map(), Array,join()
function accum(s) {
let a = s
.split('')
.map(
(val, index) =>
val[0].toUpperCase() +
val
.repeat(index + 1)
.toLowerCase()
.slice(1)
)
.join('-');
return a;
}