Using Map Flashcards
1
Q
accum(“abcd”) -> “A-Bb-Ccc-Dddd”
accum(“RqaEzty”) -> “R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy”
accum(“cwAt”) -> “C-Ww-Aaa-Tttt”
A
function accum(s) {
return […s].map((char, index) =>
(char.toUpperCase()
.char.toLowerCase()
.repeat(index)
))
.join(‘-‘)
2
Q
Step 1
A
return […s].map
This makes s an array of strings and inherits its values
3
Q
Step 2
A
((char, index)) =>
2 parameters are being mapped: the character and its respective index
4
Q
Step 3
A
make the first character upper case
char.toUpperCase() +
5
Q
Step 4
A
display the remaining characters in lower case. Using index excludes the first character (index = 0)
char.toLowerCase().repeat(index)
6
Q
Step 5
A
join them with a hyphen
.join(“-“).