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(‘-‘)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Step 1

A

return […s].map
This makes s an array of strings and inherits its values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Step 2

A

((char, index)) =>
2 parameters are being mapped: the character and its respective index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Step 3

A

make the first character upper case
char.toUpperCase() +

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Step 4

A

display the remaining characters in lower case. Using index excludes the first character (index = 0)
char.toLowerCase().repeat(index)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Step 5

A

join them with a hyphen
.join(“-“).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly