전체 글54 [Codewars] Mumbling 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 result = []; for (v.. 2024. 6. 4. [Codewars] Get the Middle Character Q. You are going to be given a word. Your job is to return the middle character of the word. If the word's length is odd, return the middle character. If the word's length is even, return the middle 2 characters. #Examples:Kata.getMiddle("test") should return "es"Kata.getMiddle("testing") should return "t"Kata.getMiddle("middle") should return "dd"Kata.getMiddle("A") should return "A" #InputA wo.. 2024. 6. 4. [Codewars] Sum of positive Q. You get an array of numbers, return the sum of all of the positives ones.Example [1,-4,7,12] => 1 + 7 + 12 = 20Note: if there is nothing to sum, the sum is default to 0. S. i > 0 조건을 사용해도 되지만 이전 문제에서 본 isNegative를 사용해봤다. isPositive도 있을줄 알았는데 없었다. 수업시간에 잠깐 본 fold 함수도 사용해봤다. reduce와 기능은 같지만 fold는 연산에 처음으로 쓰이는 값을 정ㅎ 수 있다는 차이점이 있다.int positiveSum(List arr) { return arr.where((i) => !i.isNegative.. 2024. 6. 3. [Codewars] Return Negative Q. In this simple assignment you are given a number and have to make it negative. But maybe the number is already negative? S.num makeNegative(n) => n +절댓값에 (-) 붙이는 방법, isNegative 이용하는 방법 등num makeNegative(n) => -n.abs();num makeNegative(n) => n.isNegative ? n : -n; 2024. 6. 3. 이전 1 2 3 4 5 6 ··· 14 다음