본문 바로가기
알고리즘/Codewars

[Codewars] Mumbling

by 줍 2024. 6. 4.

Q. 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.

 

S. for문 쓰는게 어색하다,,, list에 요소 추가할때는 add 쓰기!

String accum(String str) {
  List<String> result = [];
  for (var i = 0; i < str.length; i++) {
    result.add(str[i].toUpperCase() + str[i].toLowerCase() * i);
  }
  return result.join('-');
}

'알고리즘 > Codewars' 카테고리의 다른 글

[Codewars] Stop gninnipS My sdroW!  (1) 2024.06.08
[Codewars] Multiples of 3 or 5  (0) 2024.06.06
[Codewars] Get the Middle Character  (0) 2024.06.04
[Codewars] Sum of positive  (1) 2024.06.03
[Codewars] Return Negative  (0) 2024.06.03