나는 이렇게 학습한다575 1209. Grasshopper - Combine strings Combine strings function Create a function named (combine_names) that accepts two parameters (first and last name). The function should return the full name. Example: combine_names('James', 'Stevens') returns: 'James Stevens' Solution: class Names: @staticmethod def combine(a, b): return " ".join([a, b]) combine_names = Names.combine 2022. 12. 9. 1208. A Strange Trip to the Market You're on your way to the market when you hear beautiful music coming from a nearby street performer. The notes come together like you wouln't believe as the musician puts together patterns of tunes. As you wonder what kind of algorithm you could use to shift octaves by 8 pitches or something silly like that, it dawns on you that you have been watching the musician for some 10 odd minutes. You a.. 2022. 12. 8. 1207. Vowel Count Return the number (count) of vowels in the given string. We will consider a, e, i, o, u as vowels for this Kata (but not y). The input string will only consist of lower case letters and/or spaces. Solution: int getCount(String inputStr){ List arr = []; for (String s in inputStr.toLowerCase().split('')) { if (["a","e","i","o","u"].contains(s)) { arr.add(s); } } return arr.length; } import "dart:c.. 2022. 12. 7. 1206. Sum of positive ou get an array of numbers, return the sum of all of the positives ones. Example [1,-4,7,12] => 1 + 7 + 12 = 20 Note: if there is nothing to sum, the sum is default to 0. Solution: int positiveSum(List arr) { int result = 0; for (int a in arr) { if (a > 0) { result += a; } } return result; } int positiveSum(List arr) { return arr.where((l) => l > 0).fold(0, (p, c) => p + c); } import "dart:math".. 2022. 12. 6. 1205. Sum of Cubes Write a function that takes a positive integer n, sums all the cubed values from 1 to n, and returns that sum. Assume that the input n will always be a positive integer. Examples: (Input --> output) 2 --> 9 (sum of the cubes of 1 and 2 is 1 + 8) 3 --> 36 (sum of the cubes of 1, 2, and 3 is 1 + 8 + 27) Solution: int sumCubes(int n) { int result = 0; for (int i=1; i i * i * i); return l.sum; } 2022. 12. 5. 1204. Odd or Even? Task: Given a list of integers, determine whether the sum of its elements is odd or even. Give your answer as a string matching "odd" or "even". If the input array is empty consider it as: [0] (array with a zero). Examples: Input: [0] Output: "even" Input: [0, 1, 4] Output: "odd" Input: [0, -1, -5] Output: "even" Solution: String oddOrEven(List array) { int result = _sum_array(array); return res.. 2022. 12. 4. 이전 1 ··· 16 17 18 19 20 21 22 ··· 96 다음