일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- enumerate
- Python
- FOR
- decorator
- STR
- range
- len
- or
- lambda
- list
- DART
- index
- map
- join
- js
- sum
- Algorithm
- SQL
- count
- MAX
- iNT
- If
- slice
- Sorted
- and
- 파이썬
- WECODE
- 위코드
- LOWER
- split
- Today
- Total
목록DART (23)
코드로 우주평화
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..
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"..
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; }
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..
Write a function that accepts an integer n and a string s as parameters, and returns a string of s repeated exactly n times. Examples (input -> output) 6, "I" -> "IIIIII" 5, "Hello" -> "HelloHelloHelloHelloHello" Solution: String repeatString(int n, String s) { String result = ''; for (int i=0; i s * n;
Create a function with two arguments that will return an array of the first n multiples of x. Assume both the given number and the number of times to count will be positive numbers greater than 0. Return the results as an array or list ( depending on language ). Examples countBy(1,10) === [1,2,3,4,5,6,7,8,9,10] countBy(2,5) === [2,4,6,8,10] Solution: List countBy(int x, int n) { List results = [..
Is the string uppercase? Task Create a method to see whether the string is ALL CAPS. Examples (input -> output) "c" -> False "C" -> True "hello I AM DONALD" -> False "HELLO I AM DONALD" -> True "ACSKLDFJSgSKLDFJSKLDFJ" -> False "ACSKLDFJSGSKLDFJSKLDFJ" -> True In this Kata, a string is said to be in ALL CAPS whenever it does not contain any lowercase letter so any string containing no letters at..
Square(n) Sum Solution: int squareSum(List numbers) { int result = 0; for (int i in numbers) { result += i*i; } return result; } int squareSum(List n) => n.fold(0, (a, b) => a + b*b);
Complete the function which converts a binary number (given as a string) to a decimal number. Solution: int binToDec(String bin) => int.parse(bin, radix: 2);